Agent Wranglers

WEB-10Recommended

Support light and dark from the start

Say which colour schemes the page supports, with <meta name="color-scheme"> and the CSS color-scheme property. Design dark mode on purpose.

How to do it

Add the meta tag and set color-scheme: light dark on :root. Define each colour once as a token, ideally with light-dark(), as in define every colour once. Let a theme switch change color-scheme, instead of copying rules. Name the colour tokens by purpose, as Name tokens by purpose says. Email has its own rule, Plan for dark mode.

Examples

HTML example

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

CSS example

:root {
  color-scheme: light dark;
  --bg: light-dark(#ffffff, #1f2328);
  --text: light-dark(#1f2328, #f4f5fb);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
body { background: var(--bg); color: var(--text); }

How to check

The page has the meta tag and color-scheme on :root. With dark mode emulated in a browser driver and scripts blocked, body has a dark computed background and form controls render dark.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/website/html-basics/color-scheme">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.