<p>
  <div class="switch" id="the-switch-1" onclick="switchClicked(this)">
    <input name="switch-input" type="checkbox">
    <label for="switch-input">
  </div>
</p>

<p>
  <div class="switch" id="the-switch-2" onclick="switchClicked(this)">
    <input name="switch-input" type="checkbox">
    <label for="switch-input">
  </div>
</p>
.switch {
  transition: all 0.2s ease-in-out;
  cursor: pointer;
  border-radius: 15px;
  width: 50px;
  height: 30px;
  background: #6e6e70;
  display: flow-root;
}
.switch input {
  display: none;
}
.switch label {
  cursor: inherit;
  position: relative;
  height: 26px;
  width: 26px;
  border-radius: 13px;
  margin: 2px;
  background: white;
  display: block;
  left: 0;
  transition: inherit;
}
.switch.active {
  background: #57bd6a;
}
.switch.active label {
  left: 20px;
  box-shadow: -2px 0 6px 0 #3e3e4050;
}
function switchClicked(mySwitch) {
  mySwitch.classList.toggle('active')
  let checkbox = mySwitch.querySelector('input')
  checkbox.checked = !checkbox.checked
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.