We can use prefers-color-scheme: dark
to detect if dark mode is activated or not:
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
Is there a way detect if a browser supports dark mode at all? (By "supports dark mode" I mean the browser automatically changes the default background/text colors of web pages).
In CSS, we can force dark mode with
color-scheme: dark;
however, some browsers (Firefox for Android) will ignore it. So I'd like to hide theme selection if dark mode is not available.