Created
July 3, 2021 18:14
-
-
Save ab007shetty/f16ea890d093d9038b92209f6a4050f9 to your computer and use it in GitHub Desktop.
Simple Snippet to enable Dark Mode Switch
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> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<style> | |
body { | |
padding: 25px; | |
background-color: white; | |
color: black; | |
font-size: 25px; | |
} | |
.dark-mode { | |
background-color: black; | |
color: white; | |
} | |
</style> | |
</head> | |
<body> | |
<h2>Toggle Dark/Light Mode</h2> | |
<p>Click the button to toggle between dark and light mode for this page.</p> | |
<button onclick="myFunction()">Toggle dark mode</button> | |
<script> | |
function myFunction() { | |
var element = document.body; | |
element.classList.toggle("dark-mode"); | |
} | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment