@keyframes Animations & Reduced Motion
Build multi-step CSS animations like loading spinners and pulsing badges while respecting users' prefers-reduced-motion accessibility settings.
What you'll learn
- Define multi-step animations with @keyframes and animation
- Build lightweight CSS-only loading indicators and live status pulses
- Respect prefers-reduced-motion: reduce for vestibular accessibility
While transition animates between two states (e.g., default → hover), @keyframes lets you choreograph multi-step or looping animations automatically.
Respecting prefers-reduced-motion
Motion that feels playful to some users can trigger dizziness or nausea for people with vestibular disorders. Always guard decorative or looping motion with a media query:
@media (prefers-reduced-motion: reduce) {
.pulse, .spinner {
animation: none;
}
}
Fill-in-the-Blank Exercise
Accessible Keyframe Animation
Define a spin animation and disable it when the user prefers reduced motion.
@ spin {
to { transform: rotate(360deg); }
}
@media (: reduce) {
.spinner { animation: none; }
}Try It Yourself
Adjust the spinner speed or pulse keyframes below:
Check Your Understanding
1. Which CSS media query detects when a user has turned on 'Reduce Motion' in their OS settings?
Finished this lesson?
Your progress is saved locally in your browser, no account needed.