Skip to content

Detect dark mode in JavaScript

Advertisements

Check if a user’s device is in dark mode with the following code snippet.

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

console.log(isDarkMode) // result: true or false
See also  Compare JSON objects ignoring the order of the properties in JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.