liveBook · Manning

Prefers-reduced-motion

As explained in CSS in Depth, Second Edition

The prefers-reduced-motion media feature indicates whether a user has requested reduced nonessential motion.

The prefers-reduced-motion media feature detects when a user requests less nonessential motion because animations and large onscreen movements can cause discomfort for some users. section 15.1

A stylesheet-wide motion reduction rule

Put the preference check in a low-priority reset layer so it applies broadly: @layer reset { @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 very short duration preserves mechanisms that depend on transitions or animations, such as JavaScript's animationend event, instead of setting transition: none. section 15.1 section 8.1.2

The pattern combines several deliberate choices:

  • Use the reduce value to respond to a browser or operating-system motion setting. section 15.1
  • Apply !important in the reset layer because important declarations in an earlier layer outrank important declarations in later layers. section 8.1.2
  • Limit animation iterations and replace smooth scrolling as well as shortening transition and animation durations. section 15.1
@layer reset {
  @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;
    }
  }
}

Inspect the complete reset-layer listing and its declarations for animations, transitions, iteration count, and scrolling. section 15.1

How CSS in Depth, Second Edition covers it

How deep it goes
Defines a stylesheet-wide reset pattern and explains its cascade priority and event-preserving duration choice.
Examples
Uses a reset-layer universal-selector rule to shorten animations and transitions, limit iterations, and disable smooth scrolling.
What you can do after
Apply it via CSS to suppress nonessential motion when users request reduced motion while preserving transition-dependent behavior.
How it connects
Connects media queries with CSS animations, transitions, scrolling behavior, cascade layers, and !important precedence.

Also explained in

Compare how 2 books explain prefers-reduced-motion →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.