Created
June 29, 2019 09:01
-
-
Save BramEsposito/e2d94e1b0f2265344dd8f0c6a56a1f29 to your computer and use it in GitHub Desktop.
Dark mode detection with toggle
This file contains 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
<!DOCTYPE html> | |
<html> | |
<meta charset="utf-8"> | |
<head> | |
<title>Test dark mode</title> | |
<style type="text/css"> | |
body.dark { | |
background-color: #212529; | |
color: #6c757d; | |
} | |
</style> | |
<script type="text/javascript"> | |
document.addEventListener("DOMContentLoaded", function() { | |
if (window.matchMedia("(prefers-color-scheme: dark)").matches) { | |
document.body.classList.add('dark'); | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>Test dark mode <small><a href="#" onclick="document.body.classList.toggle('dark');return false;">toggle</a></small> </h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment