In this lesson, you toned down the Hawthorn Seed Library catalogue’s motion for visitors who ask their system to reduce motion. The “Returns week” banner and the filter panel now fade in instead of sliding, and the “New this week” badge keeps its pulse, only calmer.
Key Points
- Some people get dizzy or sick when parts of a page slide across the screen, so their system has a setting to reduce motion. CSS reads it through the
prefers-reduced-motionmedia feature. - To try it without changing your system, open DevTools, press Ctrl+Shift+P (Cmd+Shift+P on macOS) and choose Show Rendering. In the Rendering panel, set Emulate CSS media feature prefers-reduced-motion to
prefers-reduced-motion: reduce. Reload to replay animations that run on load. - The browser reports the setting, but nothing changes until your stylesheet asks for it with
@media (prefers-reduced-motion: reduce). - Each
animationshorthand names its keyframes, then a duration and an easing. The badge’s last value,4, is how many times it runs. - What troubles people is things traveling across the screen, zooming and parallax. A fade doesn’t move anything, so swap each slide for a fade. The
fade-inkeyframes have only afrom. With noto, the fade ends at the element’s own opacity. - Both rules select the banner, and the media query comes later in the layer, so its
animation-name: fade-inwins. It sets only the keyframes, one part of the animation shorthand. The duration and easing still come from the shorthand, so the banner fades in where it stands, over the same 0.6 seconds. - Keep gentle feedback. The badge’s pulse only changes opacity, and it’s the cue that draws the eye to a new seed. A quick, repeated blink can still pull at someone who asked for less, so under reduced motion it pulses twice over 2.4 seconds each, and still stops after 4.8 seconds.
- Watch out for a popular shortcut, one rule that sets every animation and transition to none. It stops the slides, but it takes the badge’s cue away too.
- Stopping within five seconds also keeps the badge clear of WCAG 2.2.2 Pause, Stop, Hide. It asks for a way to pause, stop or hide moving or blinking content that starts by itself, lasts more than five seconds and sits alongside other content, unless the movement is essential.
- Set the emulation back to No emulation and the page follows your own system’s setting again. If your system doesn’t ask for less motion, the slides return, because the media query only applies to people who ask.
The Final Code
The catalogue’s motion, as the starting project has it, in the components layer of styles.css: