Created
November 14, 2020 21:41
-
-
Save JohnDDuncanIII/b27934ab9dc789a961b3c6c4d46d6803 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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