What You'll Learn
You'll learn how to detect when users have requested less motion in their operating system and respect that preference in your CSS animations and transitions.
Understanding User Motion Preferences
Some users experience discomfort, nausea, or dizziness from animations and motion effects—conditions related to vestibular disorders. Modern operating systems let users indicate they prefer reduced motion, and CSS gives you a way to honor that choice.
The prefers-reduced-motion media query detects this system-level setting and allows you to adjust or disable animations accordingly.
How the Media Query Works
You use prefers-reduced-motion just like other media queries, checking for two possible values:
no-preference– User hasn't requested reduced motion (default)reduce– User has enabled reduced motion in their system settings
Here's the basic syntax:
@media (prefers-reduced-motion: reduce) {
/* Styles for users who prefer less motion */
}
Practical Example
You can scale back or eliminate animations for users who prefer reduced motion:
.animated-box {
animation: slide-in 1s ease-out;
}
@media (prefers-reduced-motion: reduce) {
.animated-box {
animation: none;
}
}
Or provide a gentler alternative:
.card {
transition: transform 0.5s;
}
@media (prefers-reduced-motion: reduce) {
.card {
transition-duration: 0.01s;
}
}
Think of it like this: It's similar to subtitles in a video—an accessibility feature that makes your content usable for everyone. You're offering an alternative experience that's still functional but respects users' needs.
Key Takeaway: Use @media (prefers-reduced-motion: reduce) to detect when users have requested less motion and provide reduced or no-animation alternatives, making your site more accessible and comfortable for everyone.