CSS light-dark() Color Generator
Pick a light and dark value for each color token, preview both themes, and copy the light-dark() CSS. Free and runs in your browser.
- Free
- No sign-up
- Runs in your browser
- Works on mobile
Try it: build your own token set
Pick a light and a dark value for each token, then toggle the preview to see the effect.
Start from an existing CSS theme
Currently showing: light
Custom properties cannot fall back by redeclaring the same name, so the fallback uses plain values, a prefers-color-scheme block, and an @supports block that upgrades to light-dark().
What the light-dark() function does
The CSS light-dark() function accepts two color values (one for light mode, one for dark mode) and returns whichever one is active, based on the page's color-scheme property. It's defined in the CSS Color Module Level 5 specification. Where the older approach required duplicating an entire block of custom properties inside a prefers-color-scheme media query, light-dark() lets you declare both values for a token in a single line:
The color-scheme: light dark; declaration is required. It tells the browser this page supports both themes, which is what light-dark() checks against.
Browser support
light-dark() is supported in all current evergreen browsers (it became Baseline "Newly available" in May 2024) and is on track to reach Baseline "Widely Available" status (the web platform's highest confidence tier) on November 13, 2026. As with any relatively recent CSS feature, check caniuse.com's current data before relying on it without a fallback if you need to support meaningfully older browser versions.
light-dark() vs. the older prefers-color-scheme pattern
| Old pattern | With light-dark() |
|---|---|
:root { --bg: white; }
@media (prefers-color-scheme: dark) {
:root { --bg: black; }
} | :root {
color-scheme: light dark;
--bg: light-dark(white, black);
} |
The old pattern duplicates the whole custom-property block per theme. With more than a handful of tokens, that duplication adds up and drifts out of sync easily. light-dark() keeps each token's two values next to each other in one place.
Related
Building out token pairs is only half the decision. Read how to actually choose your dark-theme colors, not just switch to them for the framework behind picking good values for each side of a pair, not just the CSS to declare them. And if you're naming more than a handful of tokens, Design Tokens Explained: Primitives vs. Semantic Color Tokens covers the naming structure that keeps a growing token set organized. If you need a token pair to work inside a gradient, not just a solid color, building dark-mode-aware gradients covers the technique that's actually reliably supported today.
Frequently Asked Questions
Do I still need prefers-color-scheme?
Not for the color values themselves. color-scheme: light dark; handles following the OS-level preference automatically. You'd still use a small script for a manual override toggle (letting a visitor pick a theme regardless of their OS setting), which is exactly the pattern this site's own dark-mode toggle uses.
Does light-dark() work with gradients or images?
Yes. light-dark() accepts image values, including url() and gradients, in addition to plain colors. As of September 2026 that is Baseline Newly available (Chrome and Edge 150, Firefox 150, Safari 27), so you can swap an entire background image or gradient between themes. Older browsers ignore the declaration, so keep a plain fallback line before it.
What browsers support light-dark()?
All current evergreen browsers (Chrome, Edge, Firefox, Safari) support it. Check caniuse.com's current data if you need to support older browser versions specifically.
How is this different from a JS-based dark mode toggle?
light-dark() handles the actual color-switching natively in CSS, with no JavaScript required for that part. A small script is still useful for letting a visitor manually override the OS-level theme, which is a separate concern from how the colors themselves are defined.
Sources
About this page
This page is based on MDN's light-dark() reference and the CSS Color Module Level 5 specification. Browser support keeps moving, so the page points you to caniuse.com for current numbers instead of quoting a table that would go stale. Last reviewed: October 26, 2026.