Back to CSS Checkboxes Dark Mode Toggle Pure CSS
Share
.cb-darkmode {
  display: inline-flex; align-items: center;
  gap: 10px; cursor: pointer; user-select: none;
}
.cb-darkmode__input { display: none; }
.cb-darkmode__track {
  width: 52px; height: 28px; border-radius: 14px;
  background: #1a1a2e;
  border: 1px solid rgba(255,255,255,.1);
  position: relative; transition: background .4s;
}
.cb-darkmode__thumb {
  position: absolute; top: 4px; left: 4px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; font-size: 11px;
  display: flex; align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  transition: transform .4s cubic-bezier(.23,1,.32,1);
}
.cb-darkmode__icon::before { content: "\1F319"; }
.cb-darkmode__input:checked + .cb-darkmode__track {
  background: linear-gradient(135deg, #f5a84a, #ffd700);
}
.cb-darkmode__input:checked
  + .cb-darkmode__track .cb-darkmode__thumb {
  transform: translateX(24px);
}
.cb-darkmode__input:checked
  + .cb-darkmode__track .cb-darkmode__icon::before {
  content: "\2600\FE0F";
}
<label class="cb-darkmode">
  <input class="cb-darkmode__input" type="checkbox" />
  <span class="cb-darkmode__track">
    <span class="cb-darkmode__thumb">
      <span class="cb-darkmode__icon"></span>
    </span>
  </span>
  <span>Toggle theme</span>
</label>
Live preview Edit any tab — preview updates live Ready