JSFiddle - React, Tailwind, and code Playground

by Ayyappan Sakthivadivel

HTML

<div class="checkbox-bar-holder">
  <input type="checkbox" id="toggle"/>
  <div class="checkbox-bar">
    <label for="toggle"></label>
  </div>
</div>

CSS

.checkbox-bar-holder input[type="checkbox"] {
  display: none;
}

/*Button is :CHECKED*/

.checkbox-bar-holder input[type="checkbox"]:checked ~ .checkbox-bar {
  background: #05FF00;
  box-shadow: inset 2px 0px 2px rgba(0, 0, 0, 0.15);
}

.checkbox-bar-holder input[type="checkbox"]:checked ~ .checkbox-bar label {
  left: 110px;
  transform: rotate(360deg);
}

/*'un':checked state*/

.checkbox-bar {
  height: 30px;
  width: 200px;
  background: #ff0000;
  margin-top: 38px;
  box-shadow: 0 0 2px rgba(43,43,43,1);
  border-radius: 50px;
}

.checkbox-bar label {
  height: 80px;
  width: 80px;
  background: rgba(255, 255, 255, 1);
  position: absolute;
  top: 10px;
  left: 10px;
  cursor: pointer;
  border-radius: 50px;
      transition: 400ms all ease-in-out 50ms;
  box-sizing: border-box;
  backface-visibility: hidden;
}

.checkbox-bar label::before {
  content: '';
  height: 60px;
  width: 5px;
  position: absolute;
  top: calc(50% - 30px);
  left: calc(50% - 2.5px);
  transform: rotate(45deg);
}

.checkbox-bar label::after {
  content: '';
  height: 5px;
  width: 60px;
  position: absolute;
  top: calc(50% - 2.5px);
  left: calc(50% - 30px);
  transform: rotate(45deg);
}

.checkbox-bar label::before,
.checkbox-bar label::after{
  background: rgba(43,43,43,1);
  border-radius: 5px;
}

/* pesduo class on toggle */

.checkbox-bar-holder input[type="checkbox"]:checked ~ .checkbox-bar label::before{
  height: 50px;
  top: calc(55% - 25px);
  left: calc(60% - 2.5px);
  background: rgba(73,168,68,1);
}
input[type="checkbox"]:checked ~ .checkbox-bar label::after{
  width: 20px;
  top: calc(95% - 25px);
  left: calc(22.5% - 2.5px);
  background: rgba(73,168,68,1);
}