Agent Wranglers

WEB-9Optional

Colour the browser bar to match

Set <meta name="theme-color"> twice, once for light and once for dark, so the browser's own bar matches the page. Also give body an explicit background colour.

How to do it

Add two tags with media set to light and dark. If people can switch theme, have the script insert one more tag without media before them, because the browser uses the first tag that matches. Chrome on Android and installed web apps use the tag. Safari 26 ignores it and takes its tint from the page background or a fixed bar at the top. Take both colours from the tokens in Define every colour once.

Examples

HTML example

<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#1f2328" media="(prefers-color-scheme: dark)">

How to check

The head has one tag with (prefers-color-scheme: light) and one with (prefers-color-scheme: dark), and their colours equal the page background in each mode.

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/theme-color">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.