Skip to content

Instantly share code, notes, and snippets.

@JohnDDuncanIII
Created November 14, 2020 21:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnDDuncanIII/b27934ab9dc789a961b3c6c4d46d6803 to your computer and use it in GitHub Desktop.
Save JohnDDuncanIII/b27934ab9dc789a961b3c6c4d46d6803 to your computer and use it in GitHub Desktop.
// js
const isDarkMode = (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
)
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", e => {
const colorScheme = e.matches ? "dark" : "light"
})
// css
@media (prefers-color-scheme: dark) {
background-color: black;
color: white;
}
@media (prefers-color-scheme: light) {
background-color: white;
color: black;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment