AI CSS Animations

Liquid Glass Toggle Switch

The iOS 26 switch: a wide pill knob that lifts into a clear glass lens while you hold it, showing the track through a bright rim, then springs across. The lens uses backdrop-filter.

Also known as: liquid glass switch css, ios 26 toggle switch, glass knob switch.

HTML

<label class="tgl-liquid-glass">
  <input type="checkbox" role="switch" aria-label="Bluetooth" checked>
  <span class="tgl-liquid-glass-track" aria-hidden="true">
    <span class="tgl-liquid-glass-knob"></span>
  </span>
</label>

CSS

.tgl-liquid-glass {
  --c: var(--tgl-color, #3b82f6);
  font-size: var(--tgl-size, 24px);
  position: relative;
  display: inline-block;
  vertical-align: middle;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;

}
.tgl-liquid-glass input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.tgl-liquid-glass-track {
  position: relative;
  display: block;
  width: 3.9em;
  height: 1.75em;
  border-radius: 1em;
  background: color-mix(in srgb, currentColor 13%, transparent);
  transition: background-color 0.3s ease;
}
.tgl-liquid-glass-knob {
  position: absolute;
  top: 0.125em;
  left: 0.125em;
  width: 2.4em;
  height: 1.5em;
  border-radius: 0.75em;
  background: #fff;
  box-shadow:
    0 0.1em 0.35em rgb(0 0 0 / 0.18),
    inset 0 0 0 1px rgb(255 255 255 / 0),
    inset 0.1em 0.15em 0.3em rgb(255 255 255 / 0),
    inset -0.1em -0.15em 0.3em rgb(0 0 0 / 0);
  transition:
    transform 0.5s cubic-bezier(0.34, 1.35, 0.5, 1),
    background-color 0.25s ease,
    box-shadow 0.25s ease;
}
/* the lens highlight, only while pressed */
.tgl-liquid-glass-knob::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(rgb(255 255 255 / 0.55), rgb(255 255 255 / 0.05) 55%, rgb(255 255 255 / 0.2));
  opacity: 0;
  transition: opacity 0.25s ease;
}
.tgl-liquid-glass:active .tgl-liquid-glass-knob::before { opacity: 1; }
.tgl-liquid-glass input:checked + .tgl-liquid-glass-track { background: var(--c); }
.tgl-liquid-glass input:checked + .tgl-liquid-glass-track .tgl-liquid-glass-knob { transform: translateX(1.25em); }
/* pressed: the knob lifts, grows and turns into a clear lens */
.tgl-liquid-glass:active .tgl-liquid-glass-knob {
  background: rgb(255 255 255 / 0.04);
  box-shadow:
    0 0.3em 0.8em rgb(0 0 0 / 0.16),
    inset 0 0 0 1px rgb(255 255 255 / 0.9),
    inset 0.12em 0.18em 0.25em rgb(255 255 255 / 0.75),
    inset -0.12em -0.18em 0.3em rgb(0 0 0 / 0.12);
  -webkit-backdrop-filter: blur(0.5px) brightness(1.08);
  backdrop-filter: blur(0.5px) brightness(1.08);
  transform: scale(1.3, 1.45);
}
.tgl-liquid-glass:active input:checked + .tgl-liquid-glass-track .tgl-liquid-glass-knob { transform: translateX(1.25em) scale(1.3, 1.45); }
.tgl-liquid-glass input:focus-visible + .tgl-liquid-glass-track {
  outline: 2px solid var(--c);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .tgl-liquid-glass, .tgl-liquid-glass *, .tgl-liquid-glass::before, .tgl-liquid-glass::after, .tgl-liquid-glass *::before, .tgl-liquid-glass *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --tgl-color on the element or a parent. Currently previewing #3b82f6.
  • Size: set --tgl-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 24px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar toggle switches