A site can look finished on the page and still have a plain white or grey browser bar around it on a phone. One line in the head asks the browser to color that bar to match your site. I’d add it to any site that has its own colors.
Add a theme-color meta tag with any CSS color:
<meta name="theme-color" content="#4285f4">
The media attribute lets you give a light and a dark version, so the bar follows the visitor’s system theme:
<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#111111" media="(prefers-color-scheme: dark)">
The color you pick should match the top of your page, usually the header background. If the header is a different color from the bar, the page looks cut in two.
Caveats:
- It is only a suggestion. The browser or operating system decides if and how to use it, so the result differs per platform, and some browsers ignore it.
- MDN marks it as limited availability and not Baseline, so treat it as a nicety and check the compatibility table.
- The
contentmust be a valid CSS color. A typo means no effect at all, with no error. - If your page changes theme on a button press instead of a system setting, the
mediaversions will not follow it. Then you have to update the tag’scontentfrom JavaScript yourself.
It goes well with <meta name="color-scheme"> and the prefers-color-scheme media query, which handle the look of the page itself.
Further reading: MDN: <meta name="theme-color">