DEV Community

Cover image for Dark Mode
sudo-self
sudo-self

Posted on

Dark Mode

Life is already complicated.

dark mode doesn't have to be.


add a class to an SVG to use as a toggle

class="dark-mode-svg" onclick="toggleDarkMode()"

.dark-mode {
background-color: #333;
color: grey;
}

.dark-mode-svg {
fill: #333;
color: grey;
width: 100px;
height: 100px;
margin-top: 50px;
margin-left: 900px;
cursor: pointer;

function toggleDarkMode() {
  const body = document.body;
  const isDarkMode = body.classList.contains("dark-mode");
  body.classList.toggle("dark-mode", !isDarkMode);
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay