User Preference Media Queries
User preference media queries (prefers-reduced-motion, prefers-color-scheme, prefers-contrast, forced-colors) bridge OS accessibility settings directly into CSS and window.matchMedia(). Engines re-evaluate affected stylesheets live whenever the user flips a system setting.
OS User Preference Media Query Matrix
Toggle OS-level reduced motion, color scheme, and forced-colors to inspect CSS and JS matchMedia reactions.
Under the Hood
Instead of inventing a custom settings modal per website, user preference media queries wire your stylesheet directly to the OS control panel, letting CSS Cascade Layers swap tokens in one pass.
- Motion Gate:
prefers-reduced-motion: reducetargets vestibular triggers (large GPU Compositor translations, parallax, and smooth-scrolling) while keeping subtle opacity fades. - Forced Colors Override: When
forced-colors: activetriggers (Windows High Contrast), the engine stripsbox-shadow,background-image, and customcolorvalues, mapping UI to system keywords (Canvas,CanvasText,Highlight). - JS Synchronization:
window.matchMedia('(prefers-reduced-motion: reduce)')exposes.matchesand achangeevent for WebGL, canvas, orscrollTo()animations.
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
}
@media (forced-colors: active) {
.card { border: 1px solid CanvasText; }
}Problem Genealogy
- 2010–2018 (Manual Theme Toggles & Unstoppable Parallax): Sites ignored OS dark mode and triggered motion sickness with unguarded scroll-jacking.
- 2019 (
prefers-reduced-motion&prefers-color-scheme): Browser vendors exposed macOS, iOS, Windows, and Android system flags to CSS. - 2021+ (
forced-colors&color-scheme): Replaced legacy-ms-high-contrastprefixes with standard system color palettes and native form-control theming.
Production Pitfalls
- Building focus rings with
box-shadowonly:forced-colors: activestripsbox-shadow, erasing keyboard focus indicators; always useoutline(oroutline: 2px solid transparentalongside shadows). - Forgetting JS-driven animations: CSS
@media (prefers-reduced-motion: reduce)cannot stoprequestAnimationFrameloops orelement.scrollIntoView({ behavior: 'smooth' }); checkmatchMedia()in JS.
- When not to use
forced-color-adjust: none: Only disable forced colors on color-accurate swatches or photo canvases; overriding it on buttons or text breaks contrast for low-vision users.
Connections & Logical Next Steps
Root morph transitions must respect prefers-reduced-motion: reduce to avoid vestibular discomfort.
Forcing prefers-reduced-motion disables mid-frame CSS transitions during screenshot capture.
Preference media queries override base theme tokens cleanly when structured inside cascade layers.
prefers-reduced-motion swaps large compositor transform animations for static states or subtle opacity fades.