html · level 3 · unit 3 · lesson 4
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
theme-color paints the browser in your own colours.
On many phones, the browser's top bar can take on your site's colour. This is set with <meta name="theme-color">. Its content is a : a # and six digits or letters, like #2e7d32 for leaf green.
Lots of people use . Give each theme colour a media condition, (prefers-color-scheme: light) or (prefers-color-scheme: dark), and the browser uses the first one that matches.
<meta name="color-scheme" content="light dark"> goes further. It tells the browser your page works both ways, so its own parts, like form boxes and scroll bars, can turn dark too.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Pip's Plants</title>
<meta name="theme-color" content="#2e7d32" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#0f2e12" media="(prefers-color-scheme: dark)">
<meta name="color-scheme" content="light dark">
</head>
<body>
<h1>Pip's Plants</h1>
</body>
</html> Press show my page to see it here.
Not every browser paints its bar, so the theme colour is a finishing touch, never something the page needs.
guess first
Which colour does a phone in dark mode use?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<head>
<meta name="theme-color" content="#ffcc00" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#332900" media="(prefers-color-scheme: dark)">
</head>
<body>
<h1>Honey Bee Farm</h1>
</body>
your turn
Your turn. Pick your colours.
Fill line 6 with a hex code for light mode, like #1565c0. Then fill the media on line 7 so the second colour is only for dark mode.
Press show my page to see it here.
- light mode has a hex codenot checked yet
- the dark colour is for dark modenot checked yet
fix it
Dark mode never gets its colour. Can you fix it?
Press show my page to see it here.
- the first colour has a
mediaconditionnot checked yet - the dark colour is still for dark modenot checked yet
- The browser uses the first theme colour whose
mediamatches. Which one matches every screen? - A theme colour with no
mediaalways matches, so the dark one is never reached. - Add
media="(prefers-color-scheme: light)"to the theme colour on line 6, then press run.
nailed it
the browser wears your colours. :D
theme-colortints the browser around your page.- Give each theme colour a
mediacondition, light or dark. color-schemesays your page works both ways.
new words in your collection
- theme colour
- hex code
- dark mode
This lesson isn’t saved. A free account remembers every lesson you finish.