opyeb ColorOKLCH

15 guides · Gamut

light-dark() — theme colours in one declaration

Basis 28 November 2026 · Gamut · about 7 min

light-dark() defines one colour with two values and picks one according to the used colour scheme. It replaces the pattern of declaring the same variable twice inside a media query. It shipped in Firefox 120 in late 2023, Chrome and Edge 123 and Safari 17.5 in 2024, and reached Baseline in May 2024.

Syntax and the one requirement

:root { color-scheme: light dark; }
body {
  background: light-dark(#f7f7fb, #12131a);
  color: light-dark(#1b1b22, #eceef5);
}

The function is simple but needs color-scheme: light dark. Without it the browser assumes light and never uses the second value. The property also affects form controls, scrollbars and other browser UI, which is usually desirable.

Support and fallback

BrowserVersionDate
Firefox120November 2023
Chrome · Edge123March 2024
Safari17.5May 2024
BaselineMay 2024about 91.6% of users in November 2026

For the remaining share, write a fallback. Declare the light value first, then inside @supports not (color: light-dark(#fff, #000)) set the dark value with prefers-color-scheme: dark. The export in this tool writes that structure automatically.

What belongs in light-dark()

Role tokens: background, surface, text, muted text, border, primary and on-primary, the values that differ between schemes. The palette steps themselves (brand 50 to 950) are identical in both themes, so they do not need wrapping; what changes is which step a role points to. Keeping steps static and roles dynamic is far easier to maintain.

:root {
  color-scheme: light dark;
  --brand-50: oklch(97% 0.02 250);
  --brand-950: oklch(18% 0.04 250);
  --bg: light-dark(var(--brand-50), var(--brand-950));
  --text: light-dark(var(--brand-950), var(--brand-50));
}

Things to watch

The last point matters most. If the light theme uses step 600 for the accent, dark mode should usually use step 400, one or two steps lighter, so body-size text on an accent fill keeps its contrast. The export applies that rule by default and the preview shows both themes side by side.

Browser versions and usage follow public support tables as of November 2026.

Questions

What if light-dark() is not supported?

The declaration is invalid and ignored. A fallback colour declared before it is used instead.

Can I combine it with media queries?

Yes, but mixing both confuses precedence. Keep light-dark() as the default and use media queries only in the fallback block.

How do I let users pick a theme manually?

Change color-scheme or set a data-theme attribute and override values with a selector. Leave light dark in place to follow the system.

Download the light-dark() tokens and the fallback block from the export tab.

Open the tool

Basis date 28 November 2026. Written against the W3C specifications, the APCA documentation and published browser support tables; updated when they change.

Back to the guides