Respecting reduced motion in CSS
Every animation needs an off switch for readers who ask for one.
.celebrate {
animation: xp-pop 320ms ease-out;
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.01ms;
animation-iteration-count: 1;
transition-duration: 0.01ms;
scroll-behavior: auto;
}
}
How it works
prefers-reduced-motion: reduceis a real user setting.- Cut the motion but keep the state change visible.
- Setting a near-zero duration is gentler than removing the rule.
Keywords and builtins used here
animationcelebratemediams
The run, in numbers
- Lines
- 14
- Characters to type
- 230
- Tokens
- 49
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 33 seconds.
Step 7 of 8 in Motion & effects, step 17 of 21 in Responsive & modern CSS.