This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2022.
The color-scheme CSS property allows an element to indicate which color schemes it can comfortably be rendered in. User agents change the following aspects of the UI chrome to match the used color scheme:
Component authors must use the prefers-color-scheme media feature to support the color schemes on the rest of the elements.
Common choices for operating system color schemes are "light" and "dark", or "day mode" and "night mode". When a user selects one of these color schemes, the operating system makes adjustments to the user interface. This includes form controls, scrollbars, and the used values of CSS system colors.
color-scheme: normal;
color-scheme: dark;
color-scheme: light;
<section class="default-example container" id="default-example"> <textarea id="example-element">Text Area</textarea> </section>
#example-element {
width: 80%;
height: 50%;
}
color-scheme: normal; color-scheme: light; color-scheme: dark; color-scheme: light dark; color-scheme: only light; /* Global values */ color-scheme: inherit; color-scheme: initial; color-scheme: revert; color-scheme: revert-layer; color-scheme: unset;
The color-scheme property's value must be one of the following keywords.
normalIndicates that the element can be rendered using the page's color scheme settings. If the page does not have a color scheme set, the element is rendered using the page's default color settings.
lightIndicates that the element can be rendered using the operating system light color scheme.
darkIndicates that the element can be rendered using the operating system dark color scheme.
onlyForbids the user agent from overriding the color scheme for the element.
Can be used to turn off color overrides caused by Chrome's Auto Dark Theme, by applying color-scheme: only light; on a specific element or :root.
| Initial value | normal |
|---|---|
| Applies to | all elements and text |
| Inherited | yes |
| Computed value | as specified |
| Animation type | discrete |
color-scheme =
normal |
[ light | dark | <custom-ident> ]+ && only?
To opt the entire page into the user's color scheme preferences, declare color-scheme on the :root element.
:root {
color-scheme: light dark;
}
To opt in specific elements to the user's color scheme preferences, declare color-scheme on those elements.
header {
color-scheme: only light;
}
main {
color-scheme: light dark;
}
footer {
color-scheme: only dark;
}
Along with the above CSS, also include the <meta name="color-scheme"> HTML <meta> tag in the <head>, before any CSS style information, to inform user agents about the preferred color scheme, helping prevent unwanted screen flashes during the page load.
To style elements based on color scheme preferences, use the prefers-color-scheme media query. The example below opts in the entire page to using both light and dark operating system color schemes via the color-scheme property, and then uses prefers-color-scheme to specify the desired foreground and background colors for individual elements in those color schemes.
:root {
color-scheme: light dark;
}
@media (prefers-color-scheme: light) {
.element {
color: black;
background-color: white;
}
}
@media (prefers-color-scheme: dark) {
.element {
color: white;
background-color: black;
}
}
Alternatively, use the light-dark() <color> function to set the foreground and background colors for the different color schemes using a more compact code structure:
:root {
color-scheme: light dark;
}
.element {
color: light-dark(black, white);
background-color: light-dark(white, black);
}
| Specification |
|---|
| CSS Color Adjustment Module Level 1> # color-scheme-prop> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
color-scheme |
81 | 81 | 96 | 68 | 13 | 81 | 96 | 58 | 13 | 13.0 | 81 | 13 |
dark |
81 | 81 | 96 | 68 | 13 | 81 | 96 | 58 | 13 | 13.0 | 81 | 13 |
light |
81 | 81 | 96 | 68 | 13 | 81 | 96 | 58 | 13 | 13.0 | 81 | 13 |
normal |
81 | 81 | 96 | 68 | 13 | 81 | 96 | 58 | 13 | 13.0 | 81 | 13 |
only |
9881–85 | 9881–85 | 96 | 8468–71 | 13 | 9881–85 | 96 | 6858–60 | 13 | 18.013.0–14.0 | 9881–85 | 13 |
prefers-color-scheme media query to detect user preferences for color schemes.light-dark() color function to set colors for both light and dark color schemes.color, accent-color, background-color, border-color, outline-color, text-decoration-color, text-emphasis-color, text-shadow, caret-color, and column-rule-color
background-imageprint-color-adjust
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme