JSFiddle - React, Tailwind, and code Playground

by gregfedorov

HTML

<body> 
  <p>
    <button class="off" onclick="var c=this.classList; c.toggle('on'); c.toggle('off');"></button>- a button
  </p>
  <p>
    <input type="checkbox" id="cb" checked/>- a checkbox
  </p>
</body>

SCSS

//Background
body {
  background-color: gray;    background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAFCAYAAABmWJ3mAAAAAXNSR0IArs4c6QAAADJJREFUCB1jVFRU/P9S3oMBHTCBBMUf7kARB/GZQCLIkiBBEB8sgSwJMxYuAZME0SAAAANTEwz9xqt+AAAAAElFTkSuQmCC);
  color: white;
}

//Reset webkit
input,
button {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  padding: 0;
  margin: 0;
  margin-right: 1em;
}

//Common 
input,
button {
  width: 2em;
  height: 1em;
  border-radius: 1em;
  display: inline-block;
  position: relative;
  font-size: 1em;
  vertical-align: middle;
  &:before {
    content: "";
    width: 50%;
    height: 100%;
    border-radius: 50%;
    position: absolute;
    background: rgba(white, 0.8);
    top: 0;
    left: 0;
  }
}

input[type="checkbox"] {
  background: rgba(blue, 0.7);
}

button {
  background: rgba(black, 0.7);
}

//States
input[type="checkbox"],
button {
  &:checked,
  &.on {
    &:before {
      left: auto;
      right: 0;
    }
  }
}