Preferences and forced colors
Definition and purpose
Preference media queries adapt optional styling to a user setting. Forced colors may replace author colors with a system palette; a control must remain understandable when decorative shadows disappear.
Motion preference
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { transition: transform .2s; } @media (prefers-reduced-motion: reduce) { #a { transition: none; } } </style> </head> <body> <button id="a" type="button">Continue</button> </body></html>Normal preference permits a short transition; reduced motion disables it.
Syntax and mental model
Use prefers-reduced-motion to remove nonessential transitions, not state changes. With forced-colors: active, system colors such as ButtonText and CanvasText adapt to the chosen palette. Add borders where a shadow was the sole boundary. prefers-contrast and prefers-color-scheme express different preferences; do not equate them with forced colors.
System border
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { border: 2px solid currentColor; } @media (forced-colors: active) { #a { border-color: ButtonText; } } </style> </head> <body> <button id="a" type="button">Continue</button> </body></html>A real border remains when shadows are removed.
Common mistakes
Avoid global forced-color-adjust:none. It opts out of adjustments that may be necessary for legibility.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Visual hiding and reading order. Next lesson: Accessibility audit project.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Preferences and forced colors — knowledge check
Five questions on preferences and forced colors.
What may forced colors replace?
Which query detects a motion preference?
Which color adapts to the system button text palette?
What is a robust alternative to a shadow-only boundary?
What must remain under reduced motion?