How to detect dark mode with JavaScript

05 Aug · by Tim Kamanin · 1 min read

The dark mode is all the rage now, here's how you can detect if a user has dark mode enabled:

const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches

And that's pretty much it, simple and efficient.

Want to get more 🔥 tips like this one?

Subscribe to get notified about new dev tutorials