JSFiddle - React, Tailwind, and code Playground

HTML

<input type="checkbox" class="toggle" id="t1" onchange="if(this.checked){ alert('on'); }else{ alert('off'); }" />
<label for="t1" data-width="24" data-height="24"></label>

CSS

input[type=checkbox].toggle {
    display: none;
  }
  input[type=checkbox].toggle + label {
    display: inline-block;
    position: relative;
    margin: 0;
    padding: 0;
  }
  input[type=checkbox].toggle + label::before {
    display: inline-block;
    content: "";
    width: 48px;
    height: 24px;
    border: 1px solid #efefef;
    border-radius: 14px;
    background-color: #fff;
    vertical-align: middle;
    margin: 0 5px 0 0;
  }
  input[type=checkbox].toggle + label::after {
    display: inline-block;
    content: "";
    width: 22px;
    height: 22px;
    border: 1px solid #efefef;
    border-radius: 14px;
    background-color: #fff;
    position: absolute;
    left: 0px;
    top: 1px;
    margin: 0;
    padding: 0;
  }
  input[type=checkbox].toggle:checked + label:before {
    background-color: #4BD865;
  }
  input[type=checkbox].toggle:checked + label:after {
    left: 26px;
  }