prefers-color-scheme: style a page for light or dark mode
Answer: A light or a dark color palette can be a user preference on many operating systems.
The media query
Authors use media queries to test values or features of the user agent or display device.
The test is independent of the document being rendered.
Those queries go in a CSS media rule so styles apply only in some conditions.
User preference media features arrived in Media Queries Level 5.
Sites can detect the user's preferred way to display content.
Telling the browser
Optimizing for the user's theme preferences is a good idea.
On the html element, the color-scheme property can declare light and dark support.
light and dark are the usual values for color-scheme.
A theme color can also be specified in the document head.
See also
Claims
- id: C1 claim: Media queries test features of the user agent or display. source: S1 evidence: "test and query values or features of the user agent or display device"
- id: C2 claim: User preference media features detect how the user wants content shown. source: S1 evidence: "detect the user's preferred way to display content"
- id: C3 claim: Operating systems let users prefer a light or dark palette. source: S2 evidence: "a preference for a light or a dark color palette"
- id: C4 claim: The color-scheme property can declare support for light and dark. source: S2 evidence: "color-scheme: light dark"
Sources
- [S1] prefers-color-scheme: Hello darkness, my old friend. web.dev. https://web.dev/articles/prefers-color-scheme . License: CC-BY-4.0. Accessed 2026-11-24.
- [S2] Theming. web.dev. https://web.dev/learn/design/theming . License: CC-BY-4.0. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: web.dev, prefers-color-scheme: Hello darkness, my old friend; web.dev, Theming. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: web.dev, prefers-color-scheme: Hello darkness, my old friend; web.dev, Theming. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0.
Cite this
iinventedlight. 2026. "prefers-color-scheme: style a page for light or dark mode." iinventedlight Library, iil:note:x8a07v3t, version of 2026-11-24. https://iinventedlight.com/library/notes/css-prefers-color-scheme/. License: CC-BY-4.0.
@misc{iil_note_x8a07v3t,
author = {{iinventedlight}},
title = {{prefers-color-scheme: style a page for light or dark mode}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/css-prefers-color-scheme/},
note = {Permanent ID iil:note:x8a07v3t. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- css-prefers-color-scheme.schema.json (schema; CC-BY-4.0)
- css-prefers-color-scheme.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/css-prefers-color-scheme.md.