How to add a simple dark mode
New Course Coming Soon:
Get Really Good at Git
I’ve used these few lines of CSS to apply dark mode to my website:
@media (prefers-color-scheme: dark) {
body {
filter: invert(100%);
background-color: rgb(29, 32, 31) !important;
}
img,
.astro-code,
.emoji,
iframe /* for recaptcha */ {
filter: invert(100%) !important;
}
}
Looks pretty good!
Here is how can I help you:
- COURSES where I teach everything I know
- CODING BOOTCAMP cohort course - next edition in 2025
- BOOKS 16 coding ebooks you can download for free on JS Python C PHP and lots more
- Follow me on X