CSS color-scheme

The color-scheme property tells the browser which color schemes an element can be shown in. With dark, built-in parts of the page such as form controls, scrollbars and system colors switch to their dark versions. Pick a value to see it live.

LIVEPreview

Form controls follow color-scheme:

Syntax

color-scheme: normal | light | dark | light dark | only light | only dark;

Set it on :root to cover the whole page, or on any element to change just that part. You can also declare it in HTML so the browser knows before your CSS loads: <meta name="color-scheme" content="light dark">.

Values explained

ValueWhat it does
normalThe default. The element uses the browser's standard (light) look.
lightThe element supports a light scheme only.
darkThe element supports a dark scheme: inputs, scrollbars and system colors render dark.
light darkBoth are supported, and the browser follows the visitor's system setting. The first value listed is preferred.
only light / only darkLike light or dark, and also tells the browser not to apply automatic dark-mode adjustments to the element.

What color-scheme changes (and what it doesn't)

It changes things the browser draws itself: text inputs, checkboxes, select menus, buttons, scrollbars, the default page background, and the CSS system colors such as Canvas and CanvasText. It does not recolor your own styles. If you set background: white on a card, the card stays white; you still need your own dark styles for that.

A complete dark mode setup

:root {
  color-scheme: light dark;   /* controls and scrollbars follow the system */
  --bg: #ffffff;
  --text: #1a1a2e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --text: #e5e5e5;
  }
}

body { background: var(--bg); color: var(--text); }

Modern browsers also support the light-dark() function, which picks one of two colors based on the active scheme: color: light-dark(#1a1a2e, #e5e5e5);. It only works when color-scheme allows both schemes.

Theme toggles

If your site has a light/dark switch, set color-scheme together with your own theme class so native controls match the chosen theme rather than the operating system:

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

Related tools

Frequently Asked Questions

What does color-scheme do in CSS?

It tells the browser which color schemes an element supports. With dark, the browser renders form controls, scrollbars and system colors in their dark versions.

What is the difference between color-scheme and prefers-color-scheme?

prefers-color-scheme is a media query that reads the visitor's system setting so you can change your own colors. color-scheme tells the browser which schemes your page supports so it can style its built-in controls. Most dark modes use both.

Why are my inputs still white in dark mode?

Your page is probably missing color-scheme. Add color-scheme: light dark to :root (or a color-scheme meta tag) and the browser will draw dark inputs, selects and scrollbars when dark mode is active.

Is color-scheme supported in all browsers?

Yes. Chrome, Edge, Firefox and Safari all support color-scheme. The light-dark() color function is newer but is also supported in current versions of all major browsers.

More CSS properties

Tool last updated: