Exercise objective
In this exercise, you’ll learn how to respect users’ motion preferences by implementing theprefers-reduced-motion CSS media query. This is crucial for users who suffer from vertigo, have ADHD, or are sensitive to motion.
The challenge
You’ll find a spinning animation in the course demo site (src/pages/introduction.html) that needs to be disabled when users have reduced motion preferences enabled.
The spinner element
Here’s the HTML structure of the spinner:animate-spin class applies a continuous rotation animation to this element.
Your task
Locate the exercise file
Navigate to
src/exercises/reduced-motion/reduced-motion.css in the course repository.Implement the media query
Add the This CSS rule checks if the user has enabled reduced motion in their operating system settings. If they have, it removes the spinning animation entirely.
prefers-reduced-motion media query to disable the animation:Test your implementation
Enable reduced motion in your operating system:
- Windows
- macOS
- Linux (GNOME)
- Open Settings > Ease of Access > Display
- Turn on Show animations in Windows
- Or search for “Reduce motion” in Windows Settings
Complete solution
Here’s the complete CSS solution for the exercise:reduced-motion.css
Testing with browser DevTools
You can also test this without changing your OS settings:Chrome/Edge DevTools
Chrome/Edge DevTools
- Open DevTools (F12)
- Press
Ctrl+Shift+P(orCmd+Shift+Pon Mac) to open the Command Palette - Type “reduced motion” and select Emulate CSS prefers-reduced-motion
- Choose prefers-reduced-motion: reduce
Firefox DevTools
Firefox DevTools
- Open DevTools (F12)
- Click the three dots menu > Settings
- Scroll to Advanced settings
- Under Accessibility, select prefers-reduced-motion: reduce
Best practices
Apply globally
Consider applying reduced motion preferences to all animations in your application, not just individual elements.
Use transitions
If you need some motion for functional purposes, use instant transitions instead of completely removing them:
Test with real users
If possible, test your implementation with users who actually use reduced motion settings.
Document your approach
Document which animations respect reduced motion preferences for future developers on your team.
Learn more
Reduced motion fundamentals
Learn more about why reduced motion matters and implementation patterns