Kevin Powell explains how to use the HTML color-scheme meta tag and CSS property to easily support light and dark modes.
The color-scheme property is a super useful property. It allows us to switch the UI elements, like form controls, scrollbars, and all that to light or dark modes, but it also has a meta tag that we can use as well, allowing us to create light and dark modes without even writing any CSS!
🔗 Links
✅ Polypane: a.paddle.com/v2/click/39438/133152?link=3110 (this is an affiliate link, so if you do purchase, it would also help support my channel)
✅ A really in-depth article that helped me put this video together: web.dev/color-scheme/
⌚ Timestamps
- Introduction
- The problem with the prefers-color-scheme media query
- Setting a default color-scheme
- light and dark modes with color-scheme
- Using color-scheme with prefers-color-scheme
- the color-scheme meta tag
- Setting color-scheme on individual elements
- differences between browsers
#css
--
Come hang out with other dev's in my Discord Community
💬 discord.gg/nTYCvrK
Keep up to date with everything I'm up to
✉ kevinpowell.co/newsletter
Come hang out with me live every Monday on Twitch!
📺 twitch.tv/kevinpowellcss
---
Help support my channel
👨🎓 Get a course: kevinpowell.co/courses
👕 Buy a shirt: teespring.com/stores/making-the-internet-awesome
💖 Support me on Patreon: patreon.com/kevinpowell
---
My editor: VS Code - code.visualstudio.com/
---
I'm on some other places on the internet too!
If you'd like a behind the scenes and previews of what's coming up on my YouTube channel, make sure to follow me on Instagram and Twitter.
Twitter: twitter.com/KevinJPowell
Codepen: codepen.io/kevinpowell/
Github: github.com/kevin-powell
---
And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!
Why it's here
1 person recommends this
What people say. Recommended as an excellent explanation of using the color-scheme meta tag for automatic light and dark modes.
L
Laaouatni Anason Stack Overflow • Recommends
On “light/dark mode in html, without CSS (only html)”
add this CSS property color-scheme: light dark; to the <html> css selector (is only one line of css)
OR if you need only html you can use this <meta> tag
<meta
name = "color-scheme"
content = "light dark"
/>
https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme
watch link to this video youtube video for more details: link to this video
it does all the things you listed before!
<html>
<head>
<meta name="color-scheme" content="light dark">
</head>
<body>
<h1>hello world</h1>
<span>hello world</span>
<input type="text" placeholder="hello world">
</body>
</html>