CSS color-scheme Property

The color-scheme property tells the browser which light or dark color schemes an element can support.

It allows the browser to adjust built-in interface components such as form controls, scrollbars, and system colors to match an appropriate color scheme. This helps websites integrate with a user's light or dark appearance preferences.

The property does not automatically create a complete dark theme for custom page elements. Developers must still define appropriate foreground, background, border, and other colors for their own designs.

color-scheme Syntax

The color-scheme property accepts normal or a list of supported color schemes, optionally combined with the only keyword.

selector {
  color-scheme: light dark;
}

General Syntax

selector {
  color-scheme: normal | [<ident>+ && only?];
}

In this syntax, <ident> represents a color scheme identifier such as light or dark. The plus sign indicates one or more identifiers, and only is optional.

Normal Color Scheme

.element {
  color-scheme: normal;
}

Light Color Scheme

.element {
  color-scheme: light;
}

Dark Color Scheme

.element {
  color-scheme: dark;
}

Support Light and Dark

:root {
  color-scheme: light dark;
}

Light Scheme Only

:root {
  color-scheme: only light;
}

CSS-Wide Keywords

.element {
  color-scheme: inherit;
}
.element {
  color-scheme: initial;
}
.element {
  color-scheme: unset;
}
.element {
  color-scheme: revert;
}
.element {
  color-scheme: revert-layer;
}

Property Values

The color-scheme property specifies the color schemes an element supports rather than directly assigning a foreground or background color.

Value Description
normal Does not declare support for a particular color scheme. The browser uses its default rendering behavior.
light Declares support for a light color scheme.
dark Declares support for a dark color scheme.
light dark Declares support for both light and dark schemes, allowing the browser to select an appropriate one.
dark light Declares support for both schemes, listing dark first as the preferred order when applicable.
only light Declares support for light and requests that the browser not override the element's scheme through automatic color adjustments.
only dark Declares support for dark and requests that the browser not override the element's scheme through automatic color adjustments.
only light dark Declares support for both schemes while requesting that the browser avoid automatic color overrides.

CSS-Wide Keywords

Value Description
inherit Uses the computed value from the parent element.
initial Resets the property to normal.
unset Uses the inherited value because the property is inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value normal
Inherited Yes
Applies to All elements
Computed value Specified keyword or color scheme list
Animation type Discrete
Percentages Not applicable
Primary use Declaring supported light and dark color schemes

Additional custom scheme identifiers are permitted by the syntax, but browsers primarily recognize light and dark. Custom identifiers do not automatically create new browser color schemes.

How It Works

The color-scheme property informs the browser which color schemes an element can display correctly.

Step 1: Declare Supported Schemes

:root {
  color-scheme: light dark;
}

Step 2: Determine User Preferences

The browser considers the user's appearance preferences and other relevant browser settings when selecting a used color scheme.

Step 3: Select a Supported Scheme

If the element supports both light and dark, the browser can choose the appropriate scheme. If only one scheme is supported, the browser uses that scheme for the element's built-in interface rendering.

Step 4: Adjust Browser-Provided Components

The selected scheme can affect native form controls, scrollbars, the default canvas background, and system colors.

Step 5: Style Custom Content

:root {
  color-scheme: light dark;
}
body {
  color: light-dark(#222222, #f5f5f5);
  background-color: light-dark(#ffffff, #1a1a1a);
}

Custom page colors must be defined separately. The light-dark() function is one way to select appropriate colors based on the element's used color scheme.

normal Value

The normal value indicates that the element does not explicitly declare support for a particular color scheme.

.element {
  color-scheme: normal;
}

Initial Value

normal is the initial value of the property.

Browser Rendering

With normal, the browser generally uses its default light color scheme for browser-provided interface elements, rather than assuming that the page supports dark mode.

Reset an Inherited Scheme

:root {
  color-scheme: light dark;
}
.standard-component {
  color-scheme: normal;
}

The component no longer declares the same light and dark scheme support as its parent.

When to Use normal

Use normal when you want to remove an inherited color scheme declaration and return to default browser behavior.

light Value

The light value declares that an element supports a light color scheme.

.light-panel {
  color-scheme: light;
}

Light Interface Controls

Native controls inside the element can use light-colored backgrounds and dark text, depending on browser and operating system styling.

Light Form Example

.light-form {
  color-scheme: light;
  color: #222222;
  background-color: #ffffff;
}

Nested Light Components

:root {
  color-scheme: light dark;
}
.light-component {
  color-scheme: light;
}

This allows a particular component to retain light browser-provided controls even when the surrounding page supports dark mode.

When to Use light

Use light for components designed to work with light interface colors.

dark Value

The dark value declares that an element supports a dark color scheme.

.dark-panel {
  color-scheme: dark;
}

Dark Interface Controls

Native form controls inside the element can use dark backgrounds and light foreground colors when the browser supports dark interface rendering.

Dark Form Example

.dark-form {
  color-scheme: dark;
  color: #f5f5f5;
  background-color: #1a1a1a;
}

Dark Component Inside a Light Page

:root {
  color-scheme: light;
}
.dark-component {
  color-scheme: dark;
}

The nested component can use dark browser interface styling without requiring the entire document to use dark mode.

When to Use dark

Use dark when the component is designed for dark backgrounds and light foreground colors.

Remember to provide suitable custom text and background colors rather than relying entirely on the browser.

light dark Values

Listing both light and dark declares that an element can support either color scheme.

:root {
  color-scheme: light dark;
}

Automatic Scheme Selection

The browser can select the used color scheme based on the user's preferences and available supported schemes.

Order of Values

:root {
  color-scheme: dark light;
}

The order expresses preference when the browser has no stronger reason to select a particular supported scheme. It does not necessarily override the user's light or dark preference.

Website-Wide Support

:root {
  color-scheme: light dark;
}
body {
  color: light-dark(#222222, #f5f5f5);
  background-color: light-dark(#ffffff, #1a1a1a);
}

Browser Interface Integration

When the selected scheme changes, supported browser-provided controls and system colors can adjust automatically.

When to Use Both Values

Use light dark when the website or component has been designed and tested to work correctly in both appearance modes.

only Keyword

The only keyword requests that the browser not override an element's declared color scheme through automatic color adjustments.

Light Scheme Only

.fixed-light-component {
  color-scheme: only light;
}

Dark Scheme Only

.fixed-dark-component {
  color-scheme: only dark;
}

Support Both Schemes

:root {
  color-scheme: only light dark;
}

Prevent Automatic Darkening

Some browsers may automatically adjust colors on pages that do not declare dark mode support. The only keyword can be used to request that these automatic adjustments not be applied.

Important Limitation

The only keyword does not prevent user accessibility features such as forced-colors mode from overriding colors when necessary.

When to Use only

Use only when automatic browser color adjustments would interfere with a carefully designed color scheme. Avoid using it merely to prevent users from selecting a preferred appearance.

Browser Interface Elements

The color-scheme property can influence browser-provided interface elements that are not fully styled by the author.

Form Controls

Inputs, textareas, selects, and other native controls may adjust their colors according to the selected scheme.

.dark-form {
  color-scheme: dark;
}

Scrollbars

Browser-provided scrollbars can use light or dark styling based on the element's color scheme.

.scrollable-panel {
  color-scheme: dark;
  overflow: auto;
}

Default Canvas Background

When applied to the document root, the property can influence the default canvas background color used by the browser.

System Colors

System color keywords such as Canvas and CanvasText can resolve differently in light and dark color schemes.

Browser-Specific Appearance

Native controls do not necessarily look identical across browsers or operating systems. The property selects an appropriate color scheme but does not define the exact appearance of every control.

Custom Controls

Custom-built interface elements still require explicit styling for both light and dark modes.

System Colors

CSS system color keywords represent colors selected by the browser or operating system. Their resolved values can depend on the used color scheme.

Canvas and CanvasText

.system-panel {
  color-scheme: light dark;
  color: CanvasText;
  background-color: Canvas;
}

Button Colors

.system-button {
  color: ButtonText;
  background-color: ButtonFace;
}

Link Colors

.system-link {
  color: LinkText;
}

Scheme-Dependent Results

The same system color keyword can produce different colors depending on the selected light or dark scheme.

Accessibility Benefits

System colors can help components adapt to user preferences and accessibility settings.

When to Use System Colors

Use system colors when an interface should follow browser-defined foreground and background colors rather than fixed color values.

prefers-color-scheme Media Query

The prefers-color-scheme media feature detects whether the user has expressed a preference for a light or dark appearance.

Detect Dark Mode

@media (prefers-color-scheme: dark) {
  body {
    color: #f5f5f5;
    background-color: #1a1a1a;
  }
}

Detect Light Mode

@media (prefers-color-scheme: light) {
  body {
    color: #222222;
    background-color: #ffffff;
  }
}

Combine with color-scheme

:root {
  color-scheme: light dark;
}
body {
  color: #222222;
  background-color: #ffffff;
}
@media (prefers-color-scheme: dark) {
  body {
    color: #f5f5f5;
    background-color: #1a1a1a;
  }
}

Difference Between the Features

Feature Purpose
color-scheme Declares which color schemes an element supports.
prefers-color-scheme Detects the user's light or dark appearance preference.

Important Distinction

The media query responds to the user's preference, while the color-scheme property influences the browser's used scheme for an element. They are related but not interchangeable.

Use them together when a website needs both custom theme styling and matching browser-provided controls.

light-dark() Function

The CSS light-dark() function selects between two color values based on the element's used color scheme.

Basic Syntax

.element {
  color: light-dark(#222222, #f5f5f5);
}

Enable Both Schemes

:root {
  color-scheme: light dark;
}

Text and Background

:root {
  color-scheme: light dark;
}
.panel {
  color: light-dark(#222222, #f5f5f5);
  background-color: light-dark(#ffffff, #1a1a1a);
}

Borders

.panel {
  border: 1px solid light-dark(#cccccc, #555555);
}

Color Scheme Requirement

For the dark value to be selected, the element must have a used dark color scheme. Declaring color-scheme: light dark allows the browser to choose between them.

Fallback for Older Browsers

.panel {
  color: #222222;
  background-color: #ffffff;
}
@supports (color: light-dark(black, white)) {
  .panel {
    color: light-dark(#222222, #f5f5f5);
    background-color: light-dark(#ffffff, #1a1a1a);
  }
}

The light-dark() function simplifies theme-aware color declarations, but it does not replace the need to choose accessible foreground and background combinations.

HTML Color Scheme Meta Tag

HTML provides a color-scheme metadata declaration that allows browsers to recognize supported document color schemes early in page loading.

HTML Meta Example

<meta name="color-scheme" content="light dark">

Complete Head Example

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="color-scheme" content="light dark">
  <title>Color Scheme Example</title>
</head>

CSS Equivalent

:root {
  color-scheme: light dark;
}

Why Use Metadata?

The metadata declaration can help the browser select an appropriate document color scheme before external stylesheets finish loading, reducing the chance of an incorrect initial background appearance.

Differences from CSS

The HTML metadata applies to the document's supported color schemes. The CSS property can be applied to individual elements and nested components.

Important Limitation

The metadata declaration does not automatically provide custom light and dark styles. Use CSS to define the colors of your page content.

Inheritance

The color-scheme property is inherited, allowing child elements to use the same supported color schemes as their parent.

Root Declaration

:root {
  color-scheme: light dark;
}

Inherited Component

<div class="form-container">
  <label for="email">Email Address</label>
  <input type="email" id="email">
</div>

The form controls can use the inherited color scheme when no more specific declaration overrides it.

Override a Child

:root {
  color-scheme: light dark;
}
.light-form {
  color-scheme: light;
}

Explicit Inheritance

.form-control {
  color-scheme: inherit;
}

Reset to Initial Value

.form-control {
  color-scheme: initial;
}

The initial keyword resets the property to normal.

Nested Schemes

Different parts of a document can support different color schemes. This is useful for embedding a fixed light component within a dark interface or a fixed dark component within a light interface.

Practical Uses

The color-scheme property helps websites coordinate custom designs with browser-provided interface colors.

Website-Wide Light and Dark Support

:root {
  color-scheme: light dark;
}

Dark Form Controls

.dark-form {
  color-scheme: dark;
  color: #f5f5f5;
  background-color: #1a1a1a;
}

Light Dialog

.light-dialog {
  color-scheme: light;
  color: #222222;
  background-color: #ffffff;
}

Theme-Aware Colors

:root {
  color-scheme: light dark;
}
.card {
  color: light-dark(#222222, #f5f5f5);
  background-color: light-dark(#ffffff, #252525);
  border: 1px solid light-dark(#dddddd, #555555);
}

Theme-Aware System Colors

.system-panel {
  color-scheme: light dark;
  color: CanvasText;
  background-color: Canvas;
}

Prevent Automatic Color Overrides

.fixed-light-design {
  color-scheme: only light;
}

Embedded Components

Use a local color-scheme declaration when a component needs browser-provided controls that differ from the surrounding page.

Consistent Theme Design

Combine the property with CSS custom properties, light-dark(), or prefers-color-scheme to build maintainable light and dark themes.

color-scheme Example

The following example compares native form controls inside light and dark color schemes. Both panels use the same HTML controls, but the browser can render their built-in appearance differently.

<div class="color-scheme-demo">
  <div class="scheme-panel light-panel">
    <h3>Light Color Scheme</h3>
    <label for="light-name">Your Name</label>
    <input type="text" id="light-name" placeholder="Enter your name">
    <label for="light-choice">Choose an Option</label>
    <select id="light-choice">
      <option>Option One</option>
      <option>Option Two</option>
    </select>
    <label class="checkbox-label">
      <input type="checkbox"> Subscribe to Updates
    </label>
  </div>
  <div class="scheme-panel dark-panel">
    <h3>Dark Color Scheme</h3>
    <label for="dark-name">Your Name</label>
    <input type="text" id="dark-name" placeholder="Enter your name">
    <label for="dark-choice">Choose an Option</label>
    <select id="dark-choice">
      <option>Option One</option>
      <option>Option Two</option>
    </select>
    <label class="checkbox-label">
      <input type="checkbox"> Subscribe to Updates
    </label>
  </div>
</div>
.color-scheme-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}
.color-scheme-demo .scheme-panel {
  flex: 1 1 240px;
  min-width: 0;
  padding: 20px;
  border: 1px solid #999999;
  border-radius: 6px;
}
.color-scheme-demo .light-panel {
  color-scheme: light;
  color: #222222;
  background-color: #ffffff;
}
.color-scheme-demo .dark-panel {
  color-scheme: dark;
  color: #f5f5f5;
  background-color: #252525;
}
.color-scheme-demo h3 {
  margin: 0 0 15px;
  color: inherit;
  font-size: 1.125rem;
}
.color-scheme-demo label {
  display: block;
  margin-bottom: 6px;
}
.color-scheme-demo input[type="text"],
.color-scheme-demo select {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 15px;
  padding: 8px;
}
.color-scheme-demo .checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
}
.color-scheme-demo input[type="checkbox"] {
  margin: 0;
}
Browser Result

Light Color Scheme

Dark Color Scheme

The light panel declares color-scheme: light, while the dark panel declares color-scheme: dark. The browser can use these declarations to select appropriate native control colors.

The panels also define their own text and background colors because color-scheme does not automatically style every custom element.

The exact appearance of the controls depends on the browser and operating system.

Accessibility

Supporting light and dark color schemes can improve usability by allowing browser-provided interface elements to follow an appropriate appearance.

Respect User Preferences

When a website supports both schemes, allowing the browser to select a scheme can help match the user's preferred appearance.

:root {
  color-scheme: light dark;
}

Maintain Text Contrast

Custom text and background colors must provide sufficient contrast in both light and dark modes.

.accessible-panel {
  color: light-dark(#222222, #f5f5f5);
  background-color: light-dark(#ffffff, #1a1a1a);
}

Check Form Controls

Ensure that native and custom form controls remain readable and that their focus indicators are visible in each scheme.

Forced Colors

Forced-colors mode may override author-defined colors to improve accessibility. The only keyword does not prevent these accessibility-related adjustments.

Avoid Incomplete Themes

Declaring dark mode support without providing appropriate custom styles can produce unreadable combinations, such as dark text on a dark background.

Test Both Schemes

Test headings, body text, links, form controls, borders, focus states, and error messages in both light and dark appearances.

Important Considerations

Keep the following points in mind when using color-scheme:

  • Purpose: Declares which light or dark color schemes an element supports.
  • Initial value: normal.
  • Inheritance: The property is inherited.
  • normal: Does not declare support for a specific scheme.
  • light: Declares support for light browser interface styling.
  • dark: Declares support for dark browser interface styling.
  • light dark: Allows the browser to select between both supported schemes.
  • Value order: Indicates preference when applicable but does not necessarily override the user's appearance preference.
  • only: Requests that the browser avoid automatic color scheme overrides.
  • Native controls: Can affect inputs, selects, textareas, and other browser-provided components.
  • Scrollbars: Can influence browser-provided scrollbar colors.
  • System colors: Can affect the resolved values of system color keywords.
  • Custom styles: Does not automatically create a complete light or dark theme.
  • Media queries: Can be combined with prefers-color-scheme.
  • Color functions: Can be combined with light-dark().
  • HTML metadata: The color-scheme meta tag can declare supported document schemes early in loading.
  • Animation: Changes between property values are discrete.
  • Accessibility: Maintain readable contrast and visible focus indicators in every supported scheme.
  • Browser differences: Native control appearance varies by browser and operating system.

Use color-scheme to coordinate browser-provided interface colors with your design, and provide explicit custom styles for the rest of the page.

Browser Support

The color-scheme property is widely supported in modern browsers, including Chrome, Edge, Firefox, and Safari.

Basic support for light and dark color schemes is broadly available. Newer related features, such as the light-dark() function, have separate browser compatibility requirements.

Widely Supported Example

:root {
  color-scheme: light dark;
}

Component-Level Example

.dark-component {
  color-scheme: dark;
}

Compatibility Considerations

The exact appearance of browser-provided controls and scrollbars varies across platforms. Test the results in the browsers and operating systems relevant to your project.

For current compatibility details, visit Can I Use? and search for color-scheme.

Specifications

The color-scheme property is defined in the CSS Color Adjustment specification.

CSS Color Adjustment Module Level 1

The specification defines supported color schemes, the only keyword, inheritance, and how user agents select colors for browser-provided interface components.