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

Taught in

References