WEB-31Optional
Define every colour once
Define every colour once as a light-dark() custom property, and switch themes with color-scheme, never with duplicate rules.
How to do it
Put tokens such as --paper: light-dark(#fff, #14172e) on :root. A theme switch sets data-theme, which sets color-scheme. The colour scheme rule covers the meta tag and the first paint.
Examples
CSS example
:root {
color-scheme: light dark;
--paper: light-dark(#fff, #14172e);
--ink: light-dark(#1f2328, #e8eaf6);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
body { background: var(--paper); color: var(--ink); }
How to check
Search the stylesheet. No colour values appear outside :root, apart from black stops in masks, which set transparency rather than colour.
Sources
Related rules
- WEB-9 Colour the browser bar to match in Website
- WEB-10 Support light and dark from the start in Website
- APP-1 Take every style value from design tokens in Web app interface
- APP-2 Name tokens by purpose in Web app interface
- CSS-17 Prefix a component's custom properties with its name in HTML and CSS
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/interface/colour-as-tokens">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.