Skip to content

Instantly share code, notes, and snippets.

@DesignFront
Last active September 12, 2021 20:04
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DesignFront/4df70ca40f7a077ebbc8b4c39b4c943c to your computer and use it in GitHub Desktop.
Save DesignFront/4df70ca40f7a077ebbc8b4c39b4c943c to your computer and use it in GitHub Desktop.
Detect Darkmode
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
// dark mode
}
// to watch for changes:
window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
console.log(`changed to ${e.matches ? "dark" : "light"} mode`)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment