Animations
Define the stages with @keyframes name { from { } to { } } or with percentages, then attach them using animation-name and animation-duration, or the animation shorthand. Extra controls include animation-iteration-count (infinite), animation-direction, animation-delay and animation-timing-function.
Respect users who prefer less motion by wrapping heavy animations in @media (prefers-reduced-motion: no-preference) or switching them off in a reduce query.
Example
<style>
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-40px); }
}
@keyframes pulse {
from { background: #f97316; }
to { background: #facc15; }
}
.ball { width: 50px; height: 50px; margin: 50px; border-radius: 50%; background: #f97316; animation: bounce 1s ease-in-out infinite; }
.bar { height: 30px; animation: pulse 1.2s alternate infinite; }
</style>
<div class="ball"></div>
<div class="bar"></div>Exercise
Define a set of animation stages.
@ fade { from { opacity: 0; } to { opacity: 1; } }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.