Dark Mode in One Line of Code!
Dark mode has seemingly become the desired visual mode for websites and mobile apps alike. Dark mode is easier on the eyes, especially for those like me who like to burn the midnight oil by coding and reading tutorials. Unfortunately not all websites offer dark mode, so it's up to me to remedy the situation.
Though it's not a true "dark mode", you can use CSS' filter
to create dark mode of your own:
html {
filter: invert(1);
}
Inverting colors completely via 1
will make that light-themed website much more comfortable on your eyes. It's important to realize that developers shouldn't consider this a long-term solution, as it's a quite lazy remedy and doesn't lend well to branding.
With CSS border-radius, I showed you how CSS can bridge the gap between design and development by adding rounded corners to elements. CSS gradients are another step in that direction. Now that CSS gradients are supported in Internet Explorer 8+, Firefox, Safari, and Chrome...
Sooner or later you'll run across a regular expression. With their cryptic syntax, confusing documentation and massive learning curve, most developers settle for copying and pasting them from StackOverflow and hoping they work. But what if you could decode regular expressions and harness their power? In...
I received an email from Ben Delaney a few weeks back about an interesting MooTools script he had written. His script was called FauxSelect and took a list of elements (UL / LI) and transformed it into a beautiful Mac-like SELECT element.
One of the quickest and easiest website performance optimizations is decreasing image loading. That means a variety of things, including minifying images with tools like ImageOptim and TinyPNG, using data URIs and sprites, and lazy loading images. It's a bit jarring when you're lazy loading images and they just...
Nice trick !
I would add exactly the same on all images with
Then you are even closer to a dark mode ;)
oh god no
I just tried it here and it worked, Thanks for the info.
here is the code I used:
document.querySelector('html').style.filter = 'invert(1)'
I love filter for this! You can also make the inversion less harsh by adding to the filter list:
Never EVER use this trick other than for a quick preview.
CSS filters on large areas are really bad for scrolling performance.
This isn’t quite dark mode. This is just an invert which makes images look like crap. Still, neat trick.
Thanks