AI CSS Animations

Liquid Glass Button

An Apple style liquid glass pill: the dots behind it swell in the middle and squeeze at the rim, and it springs up on hover. The refraction is an SVG displacement map, with a frosted fallback.

Also known as: apple liquid glass button css, liquid glass button css, ios 26 glass button.

HTML

<div class="gls-liquid-glass-button">
  <span class="gls-liquid-glass-button-dots" aria-hidden="true"></span>
  <span class="gls-liquid-glass-button-orb" aria-hidden="true"></span>
  <button class="gls-liquid-glass-button-btn" type="button">
    <span class="gls-liquid-glass-button-lens" aria-hidden="true"></span>
    Get started
    <svg class="gls-liquid-glass-button-arrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h13M13 6l6 6-6 6"/></svg>
  </button>
  <svg class="gls-liquid-glass-button-svg" width="0" height="0" aria-hidden="true" focusable="false">
    <filter id="gls-liquid-glass-button-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.07' stop-color='%23cc0000'/%3E%3Cstop offset='0.5' stop-color='%23800000'/%3E%3Cstop offset='0.93' stop-color='%23330000'/%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='%2300a800'/%3E%3Cstop offset='0.5' stop-color='%23008000'/%3E%3Cstop offset='0.78' stop-color='%23005700'/%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="36" xChannelSelector="R" yChannelSelector="G"/>
    </filter>
  </svg>
</div>

CSS

.gls-liquid-glass-button {
  --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(160deg, color-mix(in srgb, var(--c) 60%, #0b1026), color-mix(in srgb, var(--c) 30%, #3b0764));
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.3;
}
.gls-liquid-glass-button-dots {
  position: absolute;
  inset: -2.2em;
  background: radial-gradient(circle, rgb(255 255 255 / 0.6) 0.13em, transparent 0.15em) 0 0 / 1.1em 1.1em;
  animation: gls-liquid-glass-button-drift 5s linear infinite;
}
.gls-liquid-glass-button-orb {
  position: absolute;
  left: 3em;
  top: 1.4em;
  width: 7em;
  height: 7em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fde68a, #f472b6 45%, color-mix(in srgb, var(--c) 60%, #7c3aed) 75%, transparent 76%);
  animation: gls-liquid-glass-button-orb 7s ease-in-out infinite alternate;
}
.gls-liquid-glass-button-btn {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  padding: 1em 1.7em 1em 1.9em;
  border: 0;
  border-radius: 99em;
  background: rgb(255 255 255 / 0.06);
  color: #fff;
  font: 650 1.05em/1 system-ui, -apple-system, sans-serif;
  letter-spacing: 0.01em;
  text-shadow: 0 0.05em 0.35em rgb(0 0 0 / 0.45);
  box-shadow: 0 0.7em 1.4em -0.5em rgb(0 0 0 / 0.5);
  cursor: pointer;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
/* frosted layer: the fallback every browser draws */
.gls-liquid-glass-button-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  border-radius: inherit;
  -webkit-backdrop-filter: blur(0.12em) saturate(1.8);
  backdrop-filter: blur(0.12em) saturate(1.8);
}
/* refraction layer: Chromium bends the backdrop through the SVG map */
.gls-liquid-glass-button-lens {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  backdrop-filter: url(#gls-liquid-glass-button-lens);
}
/* specular rim and a soft top sheen */
.gls-liquid-glass-button-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgb(255 255 255 / 0.22), transparent 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);
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.gls-liquid-glass-button-arrow {
  width: 1em;
  height: 1em;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.gls-liquid-glass-button-btn:hover { transform: scale(1.07); }
.gls-liquid-glass-button-btn:hover .gls-liquid-glass-button-arrow { transform: translateX(0.2em); }
.gls-liquid-glass-button-btn:active { transform: scale(0.96); transition-duration: 0.15s; }
.gls-liquid-glass-button-btn:focus-visible { outline: 2px solid #fff; outline-offset: 0.2em; }
.gls-liquid-glass-button-svg {
  position: absolute;
  width: 0;
  height: 0;
}
@keyframes gls-liquid-glass-button-drift {
  to { transform: translate(1.1em, 1.1em); }
}
@keyframes gls-liquid-glass-button-orb {
  to { transform: translate(8.5em, 1.6em) scale(0.85); }
}

@media (prefers-reduced-motion: reduce) {
  .gls-liquid-glass-button, .gls-liquid-glass-button *, .gls-liquid-glass-button::before, .gls-liquid-glass-button::after, .gls-liquid-glass-button *::before, .gls-liquid-glass-button *::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