One method to determine if dark mode is active is by using prefers-color-scheme: dark
:
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
Is there a way to detect if a browser supports dark mode as well? (By "supports dark mode" I mean when the browser automatically changes the default background/text colors of web pages).
To enforce dark mode in CSS, we can use:
color-scheme: dark;
However, some browsers like Firefox for Android might not acknowledge this. Hence, it would be ideal to hide theme selection if dark mode is unavailable.