CSS Toggle Switch Generator

<label class="switch">
  <input type="checkbox" checked />
  <span class="slider"></span>
</label>

.switch {
  position: relative;
  display: inline-block;
  width: 56px;
  height: 30px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #cbd5e1;
  border-radius: 30px;
  transition: background 0.3s;
}

.slider::before {
  content: "";
  position: absolute;
  width: 24px;
  height: 24px;
  left: 3px;
  top: 3px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.3s;
}

.switch input:checked + .slider {
  background: #7c3aed;
}

.switch input:checked + .slider::before {
  transform: translateX(26px);
}

⚡ por MACM · miguelacm.es