Minimal dark mode styles for Hacker News
For some incomprehensible reason, the Hacker News admins won't add a dark mode. The usual workaround is to apply custom CSS with tools like Stylus (Chromium, Firefox) or Userscripts (Safari, including iOS).
There are also several custom HN web frontends, but they're often slow, and authentication doesn't work. You can use server-side proxying and inject the styles, but that's more involved, and HN can rate-limit or ban server IPs. So, using custom CSS is probably the best option until HN reconsiders.
There are plenty of dark HN themes online, but I want to share the simplest one. It works just fine for me:
@media (prefers-color-scheme: dark) {
html {
filter: invert(1) hue-rotate(180deg);
background: #fff;
}
}
invert(1) flips every color channel: light becomes dark, dark becomes light, and each color turns into its complement. hue-rotate(180deg) then rotates the hues halfway around the color wheel, approximately restoring the original colors. So light and dark are reversed, but the colors stay about the same. background: #fff gives the page a white base, which the filter changes to black.

This technique works on any site, but the more complex the original styling is, the worse the results will be. It also inverts images. HN's styles are pretty basic, so the results are fine.
While we're at it, I also like to zoom the page on wider screens to compensate for the fixed layout and tiny font size:
@media (min-width: 992px) {
html {
zoom: 1.25; /* or even 1.5 */
}
}
That's it!
★ Subscribe to keep up with new posts.