prefers-color-scheme
The CSS media feature that reports whether the user has asked their operating system for a light or dark appearance.
In more detail
@media (prefers-color-scheme: dark) applies styles when the system is in dark mode, and window.matchMedia lets scripts follow changes. Apps that offer their own toggle store the user's explicit choice, which should override the system setting.
Example
In the browser: Its values are light and dark. @media (prefers-color-scheme: dark) { :root { --surface: #1e1e1e; } } gives dark-mode users dark colours automatically.Related terms
- dark mode — A colour theme with light text on dark backgrounds, offered alongside the usual light theme.
- media query — A CSS rule, written @media, that applies styles only when a condition about the device or user settings is true.
- theming — Giving the same components different looks, such as light, dark or a different brand, by swapping the token values they use.
- CSS custom property — A property you define yourself with a double-hyphen name, such as --brand: #0066cc, and read elsewhere with var(--brand).
Taught in
- Dark Mode Strategies: System Preference, Class & High-Contrast — Design Systems & Component Engineering
- CSS Custom Properties: Scoping, Fallbacks And Theming — Frontend Architecture & Web Platform