JSFiddle - React, Tailwind, and code Playground

by techiedelight

HTML

<div id="container" class="light"></div>
<button id="mode">Dark Mode</button>

CSS

div {
  width: 500px;
  height: 300px;
  border: 1px solid black;
}

button {
  margin: 10px;
}

.light {
  background-color: #ffffff;
}

.dark {
  background-color: #243447;
}

JavaScript

document.getElementById("mode").onclick = function() {
  if (this.innerText === "Dark Mode") {
    this.innerText = "Light Mode";
  } else {
    this.innerText = "Dark Mode";
  }

  document.getElementById("container").classList.toggle("dark");
}