JavaScriptJavaScript

How to detect dark mode with JavaScript

Aug 05, 2020 · by Tim Kamanin

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

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

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

Hey, if you've found this useful, please share the post to help other folks find it:

There's even more:

Subscribe for updates

  • via Twitter: @timonweb
  • old school RSS:
  • or evergreen email ↓ ↓ ↓