javascript check if dark mode enable code example
Example 1: javascript detect dark mode
const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
Example 2: js if dark mode
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
// dark mode
}
Example 3: javascript see if chrome is in dark mode
/* Light mode */
@media (prefers-color-scheme: light) {
body {
background-color: white;
color: black;
}
}