AI CSS Animations

Liquid Glass Switch

An iOS 26 style switch on a frosted settings row. Hover or press and the white thumb swells into a clear glass lens that bends the track under it. A real checkbox, so it works with keys and forms.

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

HTML

<div class="gls-liquid-glass-switch">
  <span class="gls-liquid-glass-switch-orb gls-liquid-glass-switch-orb-a" aria-hidden="true"></span>
  <span class="gls-liquid-glass-switch-orb gls-liquid-glass-switch-orb-b" aria-hidden="true"></span>
  <label class="gls-liquid-glass-switch-row">
    <span class="gls-liquid-glass-switch-icon" aria-hidden="true">
      <svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 3c3.2 4 6 7.4 6 10.6a6 6 0 0 1-12 0C6 10.4 8.8 7 12 3z"/></svg>
    </span>
    <span class="gls-liquid-glass-switch-text">
      <span class="gls-liquid-glass-switch-name">Liquid Glass</span>
      <span class="gls-liquid-glass-switch-hint">Press the thumb</span>
    </span>
    <input type="checkbox" role="switch" checked aria-label="Liquid Glass">
    <span class="gls-liquid-glass-switch-track" aria-hidden="true">
      <span class="gls-liquid-glass-switch-thumb"><span class="gls-liquid-glass-switch-lens"></span></span>
    </span>
  </label>
  <svg class="gls-liquid-glass-switch-svg" width="0" height="0" aria-hidden="true" focusable="false">
    <filter id="gls-liquid-glass-switch-lens" x="0" y="0" width="1" height="1" color-interpolation-filters="sRGB">
      <feImage href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1' preserveAspectRatio='none'%3E%3ClinearGradient id='x'%3E%3Cstop offset='0' stop-color='%23800000'/%3E%3Cstop offset='0.15' stop-color='%23d90000'/%3E%3Cstop offset='0.5' stop-color='%23800000'/%3E%3Cstop offset='0.85' stop-color='%23260000'/%3E%3Cstop offset='1' stop-color='%23800000'/%3E%3C/linearGradient%3E%3ClinearGradient id='y' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%23008000'/%3E%3Cstop offset='0.22' stop-color='%2300bf00'/%3E%3Cstop offset='0.5' stop-color='%23008000'/%3E%3Cstop offset='0.78' stop-color='%23004000'/%3E%3Cstop offset='1' stop-color='%23008000'/%3E%3C/linearGradient%3E%3Crect width='1' height='1' fill='url(%23x)'/%3E%3Crect width='1' height='1' fill='url(%23y)' style='mix-blend-mode:screen'/%3E%3C/svg%3E" preserveAspectRatio="none" result="map"/>
      <feDisplacementMap in="SourceGraphic" in2="map" scale="18" xChannelSelector="R" yChannelSelector="G"/>
    </filter>
  </svg>
</div>

CSS

.gls-liquid-glass-switch {
  --c: var(--gls-color, #3b82f6);
  font-size: var(--gls-size, 16px);
  position: relative;
  display: grid;
  place-items: center;
  width: 22em;
  height: 12em;
  border-radius: 1.25em;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(150deg, color-mix(in srgb, var(--c) 50%, #0f172a), color-mix(in srgb, var(--c) 30%, #134e4a));
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.3;
}
.gls-liquid-glass-switch-orb {
  position: absolute;
  z-index: -1;
  border-radius: 50%;
}
.gls-liquid-glass-switch-orb-a {
  left: 2.5em;
  top: 1em;
  width: 6em;
  height: 6em;
  background: linear-gradient(135deg, #5eead4, var(--c));
  animation: gls-liquid-glass-switch-sway 7s ease-in-out infinite alternate;
}
.gls-liquid-glass-switch-orb-b {
  right: 2.8em;
  bottom: 0.8em;
  width: 5em;
  height: 5em;
  background: linear-gradient(135deg, #fde68a, #fb7185);
  animation: gls-liquid-glass-switch-sway 8s ease-in-out -4s infinite alternate-reverse;
}
.gls-liquid-glass-switch-row {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  gap: 0.7em;
  width: 15.5em;
  padding: 0.75em 0.8em;
  border-radius: 1.2em;
  box-shadow: 0 0.6em 1.5em -0.6em rgb(0 0 0 / 0.45), inset 0 1px 0 rgb(255 255 255 / 0.5), inset 0 0 0 1px rgb(255 255 255 / 0.25);
  cursor: pointer;
}
.gls-liquid-glass-switch-row::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: rgb(255 255 255 / 0.14);
  -webkit-backdrop-filter: blur(0.9em) saturate(1.5);
  backdrop-filter: blur(0.9em) saturate(1.5);
}
.gls-liquid-glass-switch-row input {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.gls-liquid-glass-switch-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 2em;
  height: 2em;
  border-radius: 0.6em;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 55%, #fff), var(--c));
}
.gls-liquid-glass-switch-icon svg { width: 1.1em; height: 1.1em; }
.gls-liquid-glass-switch-text { display: grid; flex: 1; }
.gls-liquid-glass-switch-name { font-size: 0.85em; font-weight: 650; }
.gls-liquid-glass-switch-hint { font-size: 0.65em; color: rgb(255 255 255 / 0.72); }
.gls-liquid-glass-switch-track {
  position: relative;
  flex: none;
  width: 3.9em;
  height: 1.85em;
  border-radius: 99em;
  background: rgb(255 255 255 / 0.22);
  box-shadow: inset 0 0.08em 0.2em rgb(0 0 0 / 0.25);
  transition: background-color 0.35s ease;
}
.gls-liquid-glass-switch-row input:checked + .gls-liquid-glass-switch-track { background: var(--c); }
.gls-liquid-glass-switch-row input:focus-visible + .gls-liquid-glass-switch-track { outline: 2px solid #fff; outline-offset: 0.18em; }
.gls-liquid-glass-switch-thumb {
  position: absolute;
  left: 0.18em;
  top: 0.18em;
  width: 2.35em;
  height: 1.49em;
  border-radius: 99em;
  background: #fff;
  box-shadow: 0 0.12em 0.35em rgb(0 0 0 / 0.3);
  transition: translate 0.5s cubic-bezier(0.34, 1.45, 0.64, 1), scale 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.25s ease, box-shadow 0.25s ease;
}
.gls-liquid-glass-switch-row input:checked + .gls-liquid-glass-switch-track .gls-liquid-glass-switch-thumb { translate: 1.19em 0; }
.gls-liquid-glass-switch-lens {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  backdrop-filter: url(#gls-liquid-glass-switch-lens);
  opacity: 0;
  transition: opacity 0.25s ease;
}
/* rim light and sheen, drawn above the lens */
.gls-liquid-glass-switch-thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgb(255 255 255 / 0.4), rgb(255 255 255 / 0) 55%);
  box-shadow: inset 0.08em 0.1em 0.06em -0.04em rgb(255 255 255 / 0.75),
    inset -0.08em -0.1em 0.06em -0.04em rgb(255 255 255 / 0.4),
    inset 0 0 0 1px rgb(255 255 255 / 0.22);
  opacity: 0;
  transition: opacity 0.25s ease;
}
/* hover or press: the thumb turns into a clear lens */
.gls-liquid-glass-switch-row:hover .gls-liquid-glass-switch-thumb {
  scale: 1.3 1.4;
  background: rgb(255 255 255 / 0.12);
  box-shadow: 0 0.2em 0.5em rgb(0 0 0 / 0.25);
}
.gls-liquid-glass-switch-row:hover .gls-liquid-glass-switch-lens,
.gls-liquid-glass-switch-row:hover .gls-liquid-glass-switch-thumb::after { opacity: 1; }
.gls-liquid-glass-switch-row:active .gls-liquid-glass-switch-thumb { scale: 1.45 1.55; }
.gls-liquid-glass-switch-svg {
  position: absolute;
  width: 0;
  height: 0;
}
@keyframes gls-liquid-glass-switch-sway {
  to { transform: translate(2.5em, 0.8em) scale(1.1); }
}

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

Customizing this snippet

  • Color: set --gls-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --gls-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • 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 glass effects