Sub topic 8
Respecting reduced motion preferences
This chapter assumes you know Tailwind utility classes, state variants such as hover:, and the built-in animate-* utilities from the previous chapter. You will learn how to honor the operating system setting that asks sites to reduce motion.
Why motion needs a switch
Some people get dizzy, nauseous, or distracted by large movement on screen. Vestibular disorders, migraines, and attention conditions are common causes. Operating systems offer a setting, often called "Reduce motion", to signal this. Browsers expose it to CSS as the prefers-reduced-motion media query.
The query has two useful values: no-preference (the default) and reduce. Tailwind maps these to two variants.
| Variant | Applies when |
|---|---|
| `motion-safe:` | the user has not asked for reduced motion (`no-preference`) |
| `motion-reduce:` | the user has asked for reduced motion (`reduce`) |
Two ways to use the variants
The first approach is opt-in. You attach the motion only for users who have not asked to reduce it. Without the preference, the element animates. With it, the element stays still.
<div class="size-6 rounded-full border-2 border-slate-300 border-t-indigo-600 motion-safe:animate-spin"></div>The second approach is opt-out. The motion applies to everyone, and you remove it for users who asked to reduce it.
<div class="size-6 rounded-full border-2 border-slate-300 border-t-indigo-600 animate-spin motion-reduce:animate-none"></div>Both produce the same result. Opt-in is the safer default because a forgotten opt-out leaves motion on for everyone. Opt-out is easier to retrofit onto existing markup, since you only add a class.
Removing transitions and transforms
Animations are not the only source of motion. A hover effect that scales and moves a card is also movement. Turn those off with motion-reduce:.
<div class="rounded-lg bg-white p-6 shadow transition duration-300 ease-out hover:-translate-y-1 hover:scale-105 hover:shadow-lg motion-reduce:transition-none motion-reduce:hover:transform-none">
Card content
</div>Variants stack. motion-reduce:hover:transform-none applies only when both conditions are true. Here transition-none stops the animated change, and transform-none removes the lift and zoom. The shadow still changes, but it changes instantly.
In Tailwind v4, the hover:-translate-y-1 utilities use individual CSS properties (translate, scale) rather than a single transform. If transform-none does not cancel your effect in v4, use motion-reduce:hover:translate-none and motion-reduce:hover:scale-none instead.
Replacing motion with something gentler
Removing an animation can remove meaning. A spinner tells users that work is in progress. If you set animate-none on it, a user with reduced motion sees a frozen ring and may think the page is stuck. Swap in a calmer cue instead.
<div class="flex items-center gap-2">
<div class="size-5 rounded-full border-2 border-slate-300 border-t-indigo-600 motion-safe:animate-spin"></div>
<span class="motion-reduce:animate-pulse">Loading…</span>
</div>Users who accept motion see a spinning ring. Users who reduced motion see static text that fades in and out slowly. Even animate-pulse is borderline for some people, so keep such replacements subtle, or use plain text such as "Loading…" with no animation at all.
Common errors
- Forgetting transitions. Teams disable
animate-*classes but leave hover scale and translate effects running. - Disabling only the duration. Setting
motion-reduce:duration-0stops the animation of a transition, but the transform still jumps. This is acceptable for small changes, but for large jumps, remove the transform too. - Hiding content behind motion. If an element only becomes visible at the end of an animation, a user with reduced motion must still see it. Make sure the final state is the default state.
- Not testing. Turn the setting on in your operating system, or emulate it in browser developer tools (the Rendering panel has a "prefers-reduced-motion" option), and check each animated element.
Exercise
A "Save" button has the classes transition-transform duration-200 hover:scale-110. Add classes so that users who prefer reduced motion see no scaling on hover, and explain which approach (opt-in or opt-out) you used.
Show answer
Add motion-reduce:hover:scale-100, or in Tailwind v4 motion-reduce:hover:scale-none. This is the opt-out approach: the motion applies by default and is removed for reduce. The opt-in version is motion-safe:hover:scale-110, which only applies the scale for users with no preference.
Exercise
A loading icon uses animate-spin. Why can setting motion-reduce:animate-none alone be a problem, and what would you add?
Show answer
The icon becomes a static shape, so the user may not realize the page is working. Add a non-motion cue, such as visible "Loading…" text, or a subtle alternative such as a slow animate-pulse on the label.