Does the CSS scroll-behavior property honor prefers-reduced-motion across browsers when tested without production credentials?
0 reputation · 07 May 2023, 18:56 UTC
0 reputation · 07 May 2023, 18:56 UTC
Goal: Verify that the CSS scroll-behavior:smooth property respects the prefers-reduced-motion: reduce setting across major browsers without requiring production credentials.
Constraints: Testing must be performed locally (e.g., via a development server) by toggling the prefers-reduced-motion media feature through OS settings or Chrome DevTools' rendering emulator, and the specification leaves the handling of this preference to user‑agent discretion, resulting in inconsistent implementations.
Does Chrome disable smooth scrolling when prefers-reduced-motion is set to reduce? Does Firefox honor the preference only when the media query matches? Does Safari ignore the preference for programmatic scroll?
Short answer: Chrome disables smooth scrolling when prefers-reduced-motion is set to reduce, Firefox honors the preference only when the media query matches (user‑initiated actions are suppressed, programmatic calls still animate unless the query is matched), and Safari ignores the preference for programmatic smooth scrolling.
scroll-behavior:smooth when prefers-reduced-motion: reduce is active.element.scrollIntoView({behavior:'smooth'}) unless the query is explicitly matched in CSS or JS.prefers-reduced-motion for programmatic smooth scrolling; the animation always occurs regardless of the media query setting.prefers-reduced-motion to be toggled via OS accessibility settings or Chrome DevTools’ Rendering panel. The spec grants user‑agent discretion, which explains the observed inconsistencies.The CSS scroll-behavior property is defined in a way that lets each browser decide how strictly it enforces prefers-reduced-motion. Chrome follows a stricter interpretation, disabling smooth scrolling entirely when the preference is set to reduce. Firefox implements a partial suppression: it respects the media query for user actions but leaves programmatic calls untouched unless the query is explicitly matched. Safari adopts the most permissive stance, ignoring the preference for programmatic smooth scrolling while still honoring it for native touch‑based scrolling on iOS.
scroll-behavior:smooth.
html,body{margin:0;height:100%}
#content{height:2000px;display:flex;align-items:center;justify-content:center}
#target{background:#f0f; padding:20px; border-radius:8px; scroll-behavior:smooth;}element.scrollIntoView({behavior:'smooth'}).
<button id="btn">Scroll to Target</button>
<script>
document.getElementById('btn').onclick = () => {
document.getElementById('target').scrollIntoView({behavior:'smooth'});
};
</script>prefers-reduced-motion and set it to reduce (or change the OS accessibility setting). Click the button and observe that the scroll happens instantly.@media (prefers-reduced-motion: reduce) {
* { scroll-behavior: auto !important; }
}
This forces all smooth scrolling to be disabled in all browsers when the preference is active.To refine the recommendation for your specific setup, could you let me know which browser versions and operating system you are testing on? This can affect the observed behavior, especially on older releases or mobile platforms.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.