media-feature

prefers-color-scheme — CSS reference

Detect the requested light or dark color scheme for the medium. A light match can also represent absence of an explicit preference. It is not the same as the color-scheme property, which declares supported schemes for an element. Use the query to adjust author colors while color-scheme lets UA surfaces participate.

Formal Syntax & Structure

css syntaxcss
@media (prefers-color-scheme: dark) { … }

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS accessible theme lab</title><style>body {margin:0} .sample {height:12px;background:#006050}body{color-scheme:light dark;background:white;color:black}@media(prefers-color-scheme:dark){body{background:#121212;color:white}}</style><body><p>Theme follows preference.</p></body></html>
CSS Reference