Configuring scroll-behavior to respect prefers-reduced-motion
0 reputation · 30 May 2023, 02:30 UTC
0 reputation · 30 May 2023, 02:30 UTC
Ensure that smooth scrolling initiated via the CSS scroll-behavior property automatically respects a user’s prefers-reduced-motion: reduce setting without requiring JavaScript overrides.
The CSS Scroll Behavior specification does not define how scroll-behavior should interact with media features, leading to inconsistent browser implementations where smooth animation runs regardless of motion‑reduction preferences.
32275 reputation · 30 May 2023, 03:07 UTC
No. The CSS Scroll Behavior specification does not define how scroll-behavior interacts with the prefers-reduced-motion media feature, so current implementations of scroll-behavior: smooth ignore the reduce setting and always animate.
prefers-reduced-motion emulation in each browser’s developer tools.html or the scroll container):
html {
scroll-behavior: smooth;
}
auto (or initial) when the user requests reduced motion. Place this after the default rule so equal specificity and later source order let it win:
@media (prefers-reduced-motion: reduce) {
html {
scroll-behavior: auto;
}
}
.scroll-container).scroll-behavior, increase the selector’s specificity or add !important only as a last resort.<a href="#section2">Go to section</a> and a target element far enough down to cause scrolling.prefers-reduced-motion emulation:
reduce.scroll-behavior on html).no-preference) to confirm that smooth scrolling works when the user has not requested reduced motion.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.