Sub topic 12
Reduced motion and graceful fallback
This chapter assumes you can write a CSS transition, know how display: none works, and have read the earlier chapters on @starting-style, transition-behavior: allow-discrete, popovers and dialogs. Here you will make entry and exit animations safe for people who ask for less motion, and make sure they still work when a browser lacks the newer features.
Why reduced motion matters
Some people get dizzy, nauseous or distracted by sliding, scaling and fading interface elements. Operating systems offer a "reduce motion" setting for them. Browsers expose it to CSS through the prefers-reduced-motion media feature, which has the value reduce when the setting is on.
Entry and exit animations are a common source of movement, so they need to respect this setting.
Shorten the duration, do not remove the transition
The obvious fix is transition: none. For entry and exit animations that is a mistake. The exit relies on the display transition to keep the element visible until the transition ends, and a popover or dialog relies on the overlay transition in the same way. If you remove the transitions, you can disturb the way the element is shown and hidden.
A safer approach is to keep every transition in place and make the duration almost zero:
@media (prefers-reduced-motion: reduce) {
.card,
.panel,
[popover],
dialog,
dialog::backdrop {
transition-duration: 0.01ms;
}
}With this rule the state change is effectively instant. The final states are still applied and the display flip still happens, so nothing is left stuck on screen.
A caution: transition-duration sets one value for the whole list. If a rule lists several properties with different durations, every property is given the shortened duration, which is what you want here.
Reduce movement but keep a gentle fade
Some guidance says reduced motion means less movement, not zero change. A fade does not move anything, so many teams keep it and drop only the slide or scale. You can do this by changing which properties are transitioned:
.card {
opacity: 1;
transform: translateY(0);
transition: opacity 0.4s ease, transform 0.4s ease;
@starting-style {
opacity: 0;
transform: translateY(1rem);
}
}
@media (prefers-reduced-motion: reduce) {
.card {
transition: opacity 0.2s ease;
@starting-style {
opacity: 0;
transform: none;
}
}
}In the reduced rule the card no longer starts offset, and transform is not in the transition list, so it never moves. Only the opacity changes.
Fallback for older browsers
@starting-style and transition-behavior: allow-discrete are newer than basic transitions. A browser without them ignores the unknown parts and applies the rest of your CSS. That has to leave a working page.
Check what happens in each case:
| Feature missing | What the browser does | Result |
|---|---|---|
| `@starting-style` | New elements appear at their final values | Entry is instant, content is visible |
| `allow-discrete` | `display` changes immediately | Exit is instant, content is hidden |
| `overlay` transition | Top-layer element is removed right away | Popover or dialog closes with no exit animation |
In every row the interface still works. The animation is an enhancement, not something the layout depends on. Avoid designs where the unsupported path leaves an element invisible or unclickable.
To make this deliberate, write the base state as the visible one and add effects on top. If you need to limit an effect to browsers that support a feature, wrap it in @supports:
@supports (transition-behavior: allow-discrete) {
.panel {
transition: opacity 0.3s ease, display 0.3s allow-discrete;
}
}Browsers that lack transition-behavior skip the block and use the plain state change.
How the pieces fit
Common mistakes
- Setting
transition: noneand breaking the delayeddisplayoroverlaychange. - Forgetting
dialog::backdropin the reduced-motion selector list, so the backdrop still fades slowly. - Placing the media query before the main rules. It has the same specificity, so it must come later in the source to win.
- Testing only with the setting off. Turn on reduced motion in your operating system, or emulate it in browser DevTools, and check every component.
Exercise
A teammate adds transition: none to .panel inside a reduced-motion media query. The panel uses display 0.3s allow-discrete for its exit. What goes wrong, and what would you write instead?
Show answer
Removing the transition also removes the display transition, so the delayed display: none no longer works as designed, and the exit behavior changes in ways that are hard to predict. Instead, keep the transitions and set transition-duration: 0.01ms for .panel in the media query, so the change is almost instant and display still flips correctly.
Exercise
Why does a browser without @starting-style support still show a newly inserted .card, and what does the user lose?
Show answer
The browser ignores the unknown at-rule and applies the main rule's final values, so the card appears at full opacity and position. The user loses only the entry animation.