brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: meta theme-color tints the browser bar on a phone, with a light and dark version

Web-Development
~/tips/tip-html-meta-theme-color

cat ~/tips/tip-html-meta-theme-color.md

Colors the browser toolbar to match your site, with separate light and dark values.

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 content must 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 media versions will not follow it. Then you have to update the tag’s content from 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">

More Web-Development tips ab -n 200 -c 10 https://example.com/ console.assert(items.length > 0, 'cart is empty', items) document.designMode = "on" function save(item) { Save draft All Web-Development tips (67) All topics

Link