Agent Wranglers

HTML basics Recommended

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.

Example

<meta name="color-scheme" content="light dark">
:root {
  color-scheme: light dark;
  --bg: light-dark(#ffffff, #1b1f3b);
  --text: light-dark(#1b1f3b, #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

Loading in dark mode shows no white flash. Form controls and scrollbars match.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers website playbook: https://agentwranglers.se/playbook/website/html-basics/color-scheme.