Animations run by themselves, without hover, and can have many steps.
1. Define keyframes
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-20px); }
}
2. Apply it
animation: bounce 1s ease-in-out infinite;
Animation properties
animation-name,animation-durationanimation-iteration-count— a number orinfiniteanimation-direction—normal,reverse,alternateanimation-delay,animation-timing-functionanimation-fill-mode: forwards;— keep the last frame
Respect users who prefer less motion with @media (prefers-reduced-motion: reduce).
Example
Example — Bounce and spinner
HTML
<style>
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-25px); } }
@keyframes spin { to { transform: rotate(360deg); } }
.ball { width: 50px; height: 50px; border-radius: 50%; background: tomato; margin: 30px; animation: bounce 1s ease-in-out infinite; }
.spinner { width: 40px; height: 40px; border: 5px solid #ddd; border-top-color: #1f386b; border-radius: 50%; animation: spin .8s linear infinite; margin: 20px; }
</style>
<div class="ball"></div>
<div class="spinner"></div>