A toggle switch from a checkbox

Pure CSS, still keyboard accessible.

CSS · A toggle switch from a checkboxIntermediate
.switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; transition: background 0.2s; pointer-events: none; }
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.switch input:checked + .track { background: #2563eb; }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 3px solid #93c5fd; outline-offset: 2px; }
checkboxswitchtoggleform