← All notes

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

Sources

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

Permanent ID: iil:note:x8a07v3t

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.},
}

Markdown

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.

All artifact files (JSON index)

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.