Sub topic 8
Respecting reduced motion preferences
This chapter assumes you can write Tailwind utility classes and use hover: variants. It also assumes you know the transition and animation utilities from the earlier chapters: transition, duration-*, animate-spin and custom keyframes. You don't need to know the prefers-reduced-motion media query yet. The chapter introduces it.
Why reduced motion matters
Some people get dizzy, nauseous or have headaches when a page slides, zooms, spins or scrolls on its own. This includes people with vestibular disorders, migraines and some forms of epilepsy. Others find constant motion distracting. Operating systems let users express this with a setting:
- macOS: System Settings, Accessibility, Display, "Reduce motion".
- iOS: Settings, Accessibility, Motion, "Reduce Motion".
- Windows: Settings, Accessibility, Visual effects, "Animation effects" turned off.
- Android: "Remove animations".
The browser exposes the setting to CSS as the prefers-reduced-motion media feature. It has two values:
no-preference: the user has not asked for less motion.reduce: the user has asked for less motion.
Tailwind wraps both values in variants, so you can handle them in your markup without writing media queries.
The two variants
| Variant | Generated media query | Applies when |
|---|---|---|
| `motion-safe:` | `@media (prefers-reduced-motion: no-preference)` | The user has not asked for less motion |
| `motion-reduce:` | `@media (prefers-reduced-motion: reduce)` | The user has asked for less motion |
You can put either variant in front of any utility. You can also stack them with other variants, such as motion-safe:hover:scale-105.
The spinner from the built-in animations chapter already uses this:
<div class="size-6 rounded-full border-2 border-slate-300 border-t-indigo-600 motion-safe:animate-spin"></div>With reduce set, animate-spin is never applied. The element is a static ring.
Two strategies: opt in or opt out
You can approach the variants from either direction.
Opt in with motion-safe
Write the animation only inside motion-safe:. Users with no preference get the animation. Users who asked for less motion get the plain element.
<div class="rounded-lg bg-white p-6 shadow transition duration-300 ease-out hover:shadow-lg motion-safe:hover:-translate-y-1 motion-safe:hover:scale-105">
Card content
</div>The shadow still grows on hover for everyone. The card only moves and scales for users who have not asked for less motion.
Opt out with motion-reduce
Write the animation normally and cancel it for users who asked for less motion.
<div class="animate-bounce motion-reduce:animate-none">
↓ Scroll
</div>animate-none sets animation: none, which removes the animation.
Which to choose
Opt in is safer. If you forget the variant, nobody gets motion they didn't ask for. With opt out, a forgotten motion-reduce: leaves the animation running for everyone. Opt out is convenient when you are retrofitting an existing page and want to cancel a few known animations.
Reduced motion does not mean no feedback
The setting asks for less motion. It doesn't ask you to remove every visual change. A user who reduces motion still needs to know a button is hovered, a field is focused or a request is loading.
A useful rule is to replace movement with a change that doesn't move anything. Color, opacity and shadow changes are usually fine.
| Motion that can cause trouble | Calmer replacement |
|---|---|
| Large translate or scale on hover | Color or shadow change |
| Spinning loaders | Static icon plus text, or a gentle pulse |
| Bouncing or wiggling attention-getters | Static emphasis, such as a ring or background color |
| Sliding panels across the screen | Fade in place |
| Smooth scrolling | Instant jump |
| Parallax and auto-playing background movement | A static image |
Here is a loading indicator that follows that rule:
<div role="status" class="flex items-center gap-2 text-slate-700">
<div class="size-5 rounded-full border-2 border-slate-300 border-t-indigo-600 motion-safe:animate-spin motion-reduce:animate-pulse"></div>
<span>Loading…</span>
</div>Users with no preference see a spinner. Users who reduced motion see a ring that fades in and out slowly. Both see the text label, so the state is clear even if nothing moves. The role="status" attribute also lets screen readers announce the change.
Transitions and instant state changes
Consider this button:
<button class="bg-indigo-600 px-4 py-2 text-white motion-safe:transition-colors motion-safe:duration-200 hover:bg-indigo-700">
Save
</button>Here only the transition is gated. With reduced motion on, the hover color still applies, but it switches immediately with no fade. That is a sound result: the feedback survives and the animation goes away.
A common mistake follows from this. Putting motion-safe: on a transition class does not stop a transform from applying on hover. Compare these two cards:
<!-- Still jumps 4px on hover for reduced-motion users, just without easing -->
<div class="motion-safe:transition hover:-translate-y-1">Card</div>
<!-- No translation at all for reduced-motion users -->
<div class="transition motion-safe:hover:-translate-y-1">Card</div>An instant 4px jump is a small change, but a large scale-150 jump is still a big visual change. If the effect itself is the problem, put motion-safe: on the utility that creates it, not only on the transition.
Variant order in stacked classes
You will often stack motion-safe: with hover:, group-hover: or focus:. Both orders select the same elements for these combinations, so motion-safe:hover:scale-105 and hover:motion-safe:scale-105 produce equivalent results. Pick one order and use it consistently. Tailwind v4 reads stacked variants from left to right, and v3 reads them from right to left. This difference only matters for variants that change the selector in ways that don't commute, and the motion variants aren't among them.
Smooth scrolling and JavaScript
Not all motion comes from CSS animations. Tailwind's scroll-smooth utility sets scroll-behavior: smooth, which animates every anchor jump and scrollTo call on the element. Gate it:
<html class="motion-safe:scroll-smooth">Animations driven by JavaScript don't see your Tailwind variants. If you call scrollIntoView with a smooth behavior, or use a JS animation library, check the same media feature yourself:
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
function scrollToSection(element) {
element.scrollIntoView({
behavior: reduceMotion.matches ? "auto" : "smooth",
});
}
// The user can change the OS setting while the page is open.
reduceMotion.addEventListener("change", (event) => {
console.log("Reduce motion is now", event.matches ? "on" : "off");
});matchMedia returns a live object. Its matches property is current each time you read it, so you don't need to cache the result.
Custom animations
Animations you define yourself are not safe by default. A utility such as animate-wiggle runs for everyone unless you gate it:
<button class="motion-safe:animate-wiggle rounded bg-amber-500 px-4 py-2">
Notifications
</button>If you are defining the keyframes in a Tailwind v4 theme, this is the definition behind that class:
@import "tailwindcss";
@theme {
--animate-wiggle: wiggle 0.4s ease-in-out 2;
@keyframes wiggle {
0%, 100% { transform: rotate(-3deg); }
50% { transform: rotate(3deg); }
}
}The theme doesn't know about user preferences, so the gating belongs in the markup. Teams that worry about forgetting it often agree on a rule: custom animation classes are never used without motion-safe: or motion-reduce:animate-none.
A global safety net
If you have a large page and can't audit every element, add a base rule that shortens all animations and transitions when the user asks for reduced motion:
@import "tailwindcss";
@layer base {
@media (prefers-reduced-motion: reduce) {
*,
::before,
::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
}
}The tiny duration, rather than 0s or none, makes animationend and transitionend events still fire, so JavaScript that waits for them keeps working. The !important flags are needed because utilities like duration-300 would otherwise win.
This rule is blunt. It also removes small, harmless transitions and slows down nothing in a smart way. Treat it as a backstop for code you haven't reviewed, and keep designing individual animations with motion-safe: and motion-reduce:.
Testing
You don't need to change your OS settings to test.
- Open Chrome or Edge DevTools and press
Ctrl+Shift+P(Cmd+Shift+Pon macOS). - Run "Show Rendering".
- Find "Emulate CSS media feature prefers-reduced-motion" and select "reduce".
- Reload and interact with the page.
Firefox has a similar toggle in the Inspector's Rules panel, under the color scheme and print simulation buttons. Test both values. Check that every loading state, hover effect and entrance animation still communicates what it should when nothing moves.
Common errors
- Gating the
transitionbut not the transform, so the jump remains (see above). - Removing a spinner for reduced-motion users and offering nothing in its place, so the loading state has no indicator.
- Forgetting JavaScript-driven motion and
scroll-smooth. - Using
motion-reduce:utilities such asmotion-reduce:transition-noneand assuming this also covers custom keyframe animations. It doesn't. Those needmotion-reduce:animate-none. - Testing only with the setting off.
Exercise
A card has the classes transition duration-300 hover:-translate-y-2 hover:scale-110. A user with reduced motion enabled still sees the card change size and position on hover, just instantly. Rewrite the classes so that the card keeps a visible hover response without any movement or scaling for that user, and say what the hover response is.
Show answer
Use transition duration-300 hover:shadow-lg motion-safe:hover:-translate-y-2 motion-safe:hover:scale-110. The transforms now only apply when the user has not asked for reduced motion, and the shadow change is the hover feedback for everyone. Gating only the transition would not have been enough, because the transform would still apply instantly.
Exercise
You use element.scrollIntoView({ behavior: "smooth" }) in a script and scroll-smooth on the html element. Which changes make both respect reduced motion?
Show answer
Change the class to motion-safe:scroll-smooth. In the script, read window.matchMedia("(prefers-reduced-motion: reduce)").matches and pass behavior: "auto" when it is true, otherwise "smooth". Tailwind variants only affect CSS, so JavaScript has to check the media feature itself.