Operating systems let people choose a light or dark appearance, and browsers expose that choice through the prefers-color-scheme media feature. Matching the page colors to that preference keeps text, panels, links, and controls from looking out of place when the rest of the device is already dark.
Use prefers-color-scheme for authored colors and color-scheme for browser-provided parts such as form controls, scrollbars, and default surfaces. CSS custom properties keep the light and dark palettes in one place so components can read the same token names in both modes.
A light palette outside the media query provides the fallback when no dark preference is reported. The browser updates the CSS when the preference changes, without JavaScript; Chrome can emulate both preferences without changing the operating system's appearance.
Steps to support system dark mode with CSS:
- Create index.html in an empty folder using your text editor.
- index.html
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="color-scheme" content="light dark"> <title>System color preference</title> <link rel="stylesheet" href="styles.css"> </head> <body> <main class="card"> <h1>Reading preferences</h1> <p>The page follows your system's light or dark appearance.</p> <label for="size">Text size</label> <select id="size"> <option>Standard</option> <option>Large</option> </select> <p><a href="#details">About these colors</a></p> <p id="details">Both themes keep text and controls readable.</p> </main> </body> </html>
The color-scheme meta tag advertises light and dark support before the stylesheet loads. The linked stylesheet supplies the page colors.
- Create styles.css beside index.html with the light palette.
- styles.css
:root { color-scheme: light; --color-page: #f8fafc; --color-surface: #ffffff; --color-text: #111827; --color-muted: #4b5563; --color-border: #cbd5e1; --color-accent: #2563eb; }
- Append the page and component styles to styles.css.
- styles.css
body { margin: 0; padding: 1.5rem; font: 1rem/1.5 system-ui, sans-serif; background: var(--color-page); color: var(--color-text); } .card { max-width: 30rem; padding: 1.5rem; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 0.75rem; } h1 { margin-top: 0; font-size: 1.5rem; } p { color: var(--color-muted); } a { color: var(--color-accent); } select { margin-left: 0.5rem; padding: 0.25rem; font: inherit; }
The select control keeps its native background and text colors. The color-scheme property lets the browser match those colors to the theme.
- Append the dark preference rule at the end of styles.css.
- styles.css
@media (prefers-color-scheme: dark) { :root { color-scheme: dark; --color-page: #0f172a; --color-surface: #1e293b; --color-text: #e2e8f0; --color-muted: #94a3b8; --color-border: #475569; --color-accent: #38bdf8; } }
The same custom-property names supply both themes. Setting color-scheme: dark inside the query switches native controls along with the authored palette.
- Save index.html and styles.css.
- Open index.html in Chrome.

- Open Chrome DevTools with F12.
On macOS, the shortcut is Command + Option + I. The initial page follows the browser's current preference.
- Open the DevTools Command Menu with Ctrl + Shift + P.
On macOS, the shortcut is Command + Shift + P.
- Run Show Rendering from the Command Menu.

- Select prefers-color-scheme: light in the Rendering panel's Emulate CSS media feature prefers-color-scheme dropdown.
The light branch uses a pale page, a white card, dark text, a blue link, and a light native select control.
- Select prefers-color-scheme: dark in the same dropdown.

- Confirm that the page and native select control use readable dark-theme colors.
The page and card should turn dark while the text and link become lighter. A white control on the dark page usually means color-scheme is missing or a fixed control background overrides it. Native control shades vary between browsers. No emulation returns Chrome to the device's preference.