docs.rodeo

MDN Web Docs mirror

color-scheme

{{CSSRef}} 

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.

{{EmbedInteractiveExample("pages/css/color-scheme.html")}} 

Syntax

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.

Values

Formal definition

{{cssinfo}} 

Formal syntax

{{csssyntax}} 

Examples

Declaring color scheme preferences

To opt the entire page into the user’s color scheme preferences, declare color-scheme on the {{cssxref(":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;
}

Styling based on color schemes

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);
}

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN