CSS Function
color-scheme
The color-scheme property declares which color schemes an element supports (light, dark, or both), affecting UA default styles.
Syntax
color-scheme: normal | [ light | dark ]+ | only light | only darkParameters
| Name | Type | Required | Description |
|---|---|---|---|
| normal | keyword | No | No color scheme preference indicated |
| light | keyword | No | Element supports light color scheme |
| dark | keyword | No | Element supports dark color scheme |
| only | keyword | No | Prevents UA from overriding the color scheme |
Examples
Support both schemes
Tells the browser the page supports both light and dark modes.
css
:root {
color-scheme: light dark;
}Force dark on element
Forces dark UA styles on a specific element.
css
.dark-widget {
color-scheme: only dark;
}Meta tag equivalent
HTML meta tag for early color scheme hinting.
html
<meta name="color-scheme" content="light dark">Browser Support
✓
Chrome
v81++
✓
Firefox
v96++
✓
Safari
v12.1++
✓
Edge
v81++
✓
Opera
v68++
Tailwind Equivalent
You can achieve similar results in Tailwind CSS using the following utility classes:
Tailwind dark mode is configured via darkMode in tailwind.config.js (class or media strategy)Frequently Asked Questions
What does color-scheme actually change?▼
It affects UA stylesheet defaults: form controls, scrollbars, selection colors, and default text/background colors adapt to the declared scheme.
Should I use the CSS property or meta tag?▼
Use both. The meta tag prevents a flash of incorrect colors on page load. The CSS property allows finer per-element control.
Explore CSS Color Tools
Try our free tools to work with color-scheme and other CSS color functions.
Open Tools