Live data from Hacker News

Dark mode in a website with CSS

tombrow.com

111–120 of 191 posts

Re: Dark mode in a website with CSS

#111

The problem is that this doesn't let the user toggle dark mode on/off. If you want the user to be able to toggle dark mode on your site without changing their Operating System preferences, then you'll need to implement your dark theme as a class (eg. body.theme-dark) since there's no way to dynamically set the media query. const darkMode = window.matchMedia('(prefers-color-scheme: dark)') if (darkMode) { document.bod…

We have a design system that supports both black text on white and white text on black (as a contrasting block of content).

If we want to support dark mode now we have to support four different options. Writing that with a combination of classes and media queries is going to be a nightmare:

   .default-theme h2 { background: white; color: black }
   .inverted-theme h2 { background: black; color: white }

   @media (prefers-color-scheme: dark) {
     .default-theme h2 { background: black; color: white }
     .inverted-theme h2 { background: white; color: black }
   }

Your trick might make this a little more palatable.

Re: Dark mode in a website with CSS

#112
post #92

Earlier quoted context omitted.

The easy option is to just put a white background behind the diagrams. It might not be as pretty as having the image designed right for a black background but its better than that hack.

that can be like a lighthouse in a dark night. flux can help of course, but if you are serious about supporting dark mode then you should eliminate as much white space as managable.

I think he means if you're serious about dark mode then design two graphs one light, one dark. Solving "how do I turn a well designed light mode image into a dark mode image" is an AI task that would be a nice research paper, not something a designer can hack together with a bunch of if-then rules.

Re: Dark mode in a website with CSS

#113

I love dark mode as a user, but as a developer it terrifies me how much complexity is involved in programming in 2019. At a stroke, it doubles the number of possible combinations of: - 2 device sizes: desktop vs mobile (e.g. responsive) - 3 platforms: web vs iOS vs Android, or web vs Windows vs macOS vs Linux (not even counting cross-browser or OS version quirks), or god forbid all of the above - 2 input methods: hov…

That's 48 combinations to design and test for.

And then imagine if your web site is multilingual...

Re: Dark mode in a website with CSS

#114

Earlier quoted context omitted.

Why mess with content colors? Just leave the images.

If you have a lot of images with white backgrounds, that's going to defeat the purpose of Dark Mode. Some people prefer dark mode because they suffer migraines and bright lights are a problem when they have a migraine. Or homeless people may be using it for both stealth purposes and battery conservation when they have limited opportunities to recharge. For some people, this preference is not just some minor detail. I…

> Or homeless people may be using it for both stealth purposes and battery conservation when they have limited opportunities to recharge.

Sorry, what? I feel like this is a very contrived reason to support dark mode in your interface, if it even helps…

Re: Dark mode in a website with CSS

#115
post #55
post #5

I’m probably not representative of the general dark mode user, I think, but I enable dark mode because I want the UI chrome out of the way to concentrate on the content. I don’t want dark content. Is there a way to disable this media query?

Ditto. Duckduckgo seems to have added support, but has a preference to keep it light. I enabled light (despite system dark for reason above) but it means any new tab search flashes dark for a fraction of a second, before it reads the lightness preference cookie or whatever.

Annoyingly, DuckDuckGo doesn't let me set an adaptive theme if I change the font settings, plus they don't have an easy way to contact them either…

Re: Dark mode in a website with CSS

#116

Earlier quoted context omitted.

If you have a lot of images with white backgrounds, that's going to defeat the purpose of Dark Mode. Some people prefer dark mode because they suffer migraines and bright lights are a problem when they have a migraine. Or homeless people may be using it for both stealth purposes and battery conservation when they have limited opportunities to recharge. For some people, this preference is not just some minor detail. I…

> Or homeless people may be using it for both stealth purposes and battery conservation when they have limited opportunities to recharge. Sorry, what? I feel like this is a very contrived reason to support dark mode in your interface, if it even helps…

Contrived: deliberately created rather than arising naturally or spontaneously. Synonym: deliberate

created or arranged in a way that seems artificial and unrealistic. Synonym: forced

----

People can do anything they want with their websites. I'm not anyone who sets global policy on what your website should do.

But there's nothing contrived about the comment. It's an unplanned, spontaneous thought based on first-hand experience.

I spent nearly six years homeless. I'm quite open about that. I still blog about homelessness.

I spent a lot of time online while homeless. This was written about me:

http://alexandralindelof.com/story-package/

Re: Dark mode in a website with CSS

#117

Earlier quoted context omitted.

> Or homeless people may be using it for both stealth purposes and battery conservation when they have limited opportunities to recharge. Sorry, what? I feel like this is a very contrived reason to support dark mode in your interface, if it even helps…

Contrived: deliberately created rather than arising naturally or spontaneously. Synonym: deliberate created or arranged in a way that seems artificial and unrealistic. Synonym: forced ---- People can do anything they want with their websites. I'm not anyone who sets global policy on what your website should do. But there's nothing contrived about the comment. It's an unplanned, spontaneous thought based on first-hand…

I'm aware of that, but images on a website being desaturated or having a dark background doesn't seem like it would help. (I do agree with your appeal to those who are sensitive to bright lights, FWIW. It's just that this one sounds like a bit of a reach.)

Re: Dark mode in a website with CSS

#118

Wikipedia needs this. yes yes there's browser plugins, but I'd rather not have some rando plugin potentially reading every site I visit to load a dark mode plugin on the ones it recognizes.

You can try https://en.wikipedia.org/wiki/User:Volker_E._(WMF)/dark-mode for now. It's a black/night mode at the moment. And (not yet) an official option with some technical acceptance issues like lazy-loading, therefore flicker on load. – I work for the Wikimedia Foundation. This wish has been stated as part of the Community Wishlist survey 2019. https://meta.wikimedia.org/wiki/Community_Wishlist_Survey_20...

Re: Dark mode in a website with CSS

#119
Slightly off topic,

I find it kind of ironic that there's so much debate surrounding the intricacies of dark mode support on a forum with no dark mode support (even though it avoids 90% of the gotchas).

Re: Dark mode in a website with CSS

#120
post #4

I did this recently for my new personal website! It's quite easy and really satisfying. I love doing as much as possible in stateless CSS instead of JavaScript. http://www.brandonsmith.ninja/

I like that you're using CSS variables to achieve this. I had to look up support for this , and it seems fairly decent. https://caniuse.com/#feat=css-variables
Post reply on HN