Skip to content
UISpell
Engineering

Liquid Glass Button: CSS, Tailwind and React Code That Holds Up

A liquid glass button is three layers: refraction, a specular edge, and a press that squishes. Copy the CSS, Tailwind and React versions, plus the fallbacks nobody ships.

Liquid Glass Button: CSS, Tailwind and React Code That Holds Up

Most liquid glass buttons are frosted rectangles. They blur what is behind them, add a white border, and call it done. The result reads as plastic because glass has two other jobs: it bends the light along its edge, and it responds to pressure like a solid object rather than a CSS transition.

The demo below has three layers, no keyframes, and one state that matters — pressed.

Live demo · Liquid glass buttons over a lit scene Open full screen
Move the pointer across a button to see the specular highlight follow. Press and hold to feel the squish.

The three layers

LayerJobImplementation
RefractionDistort and tint what is behindbackdrop-filter: blur() saturate() brightness() plus a translucent gradient fill
Specular edgeCatch light along the rimInset top highlight, inset bottom bounce, a 1px gradient border
Press physicsMove toward the surface, not awayscale(0.962) and a smaller shadow, on a spring-like curve

If you drop the third layer the button still looks fine in a screenshot and feels dead in the hand. That asymmetry is why so many demos ship with only the first two.

Liquid glass buttons over a dark scene lit by orange, blue and violet light

The same three layers on a dark scene. Nothing in the CSS changes — brightness lifts the fill and the saturated backdrop keeps the color behind the glass alive.

Layer 1 — refraction

backdrop-filter is the whole trick, and it only works when there is something worth blurring. A glass button on a flat white background will always look like a gray pill. Put it over a colored scene, an image, or a textured surface, then let the filter do the work.

.glass {
  background: linear-gradient(150deg, rgb(255 255 255 / 0.42), rgb(255 255 255 / 0.12));
  -webkit-backdrop-filter: blur(14px) saturate(180%) brightness(1.08);
  backdrop-filter: blur(14px) saturate(180%) brightness(1.08);
  border: 1px solid rgb(255 255 255 / 0.45);
}

Three numbers matter. Blur controls how much of the background survives — 10–16px reads as glass, 24px reads as fog. Saturate is what makes the tint feel alive; below 140% the result looks washed out. Brightness above 1 lifts the glass off a dark scene without changing the fill.

Layer 2 — the specular edge

Glass has a bright rim where it turns away from the viewer and a dimmer bounce on the opposite side. Two inset shadows plus a gradient border approximate it.

.glass {
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.55),
    inset 0 -1px 0 rgb(255 255 255 / 0.16),
    0 18px 40px -18px rgb(15 12 40 / 0.45);
}

The two insets do the rim. The third shadow is the button’s contact shadow and is the one you remove on press.

For the moving highlight, don’t animate a gradient — track the pointer and move a radial gradient with a CSS variable. It costs one pointermove handler and looks like the light is following the hand.

.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(
    180px 120px at var(--mx, 30%) var(--my, 0%),
    rgb(255 255 255 / 0.55),
    transparent 70%
  );
  opacity: 0;
  transition: opacity 240ms ease;
  pointer-events: none;
}
.glass:hover::before,
.glass:focus-visible::before {
  opacity: 1;
}
el.addEventListener("pointermove", (event) => {
  const rect = el.getBoundingClientRect();
  el.style.setProperty("--mx", `${((event.clientX - rect.left) / rect.width) * 100}%`);
  el.style.setProperty("--my", `${((event.clientY - rect.top) / rect.height) * 100}%`);
});

Layer 3 — press physics

A button that scales down and keeps its shadow looks like it is shrinking away from you. A button that scales down and loses its contact shadow looks like it is moving into the surface. The timing curve does the rest.

.glass:active {
  transform: scale(0.962);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.4),
    inset 0 -1px 0 rgb(255 255 255 / 0.1),
    0 8px 20px -14px rgb(15 12 40 / 0.5);
  transition-duration: 90ms;
}
.glass {
  transition:
    transform 260ms cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 200ms ease;
}

Release returns on the overshoot curve; press lands fast with 90ms. That asymmetry — slow spring back, fast press — is most of the “physical” feel.

Tailwind version

Utilities handle the fill, border and backdrop filter. The pseudo-element layers need real CSS, because ::before is not a utility.

<button class="relative isolate rounded-2xl border border-white/45
  bg-[linear-gradient(150deg,rgb(255_255_255/0.42),rgb(255_255_255/0.12))]
  px-6 py-3.5 text-sm font-medium text-zinc-950
  backdrop-blur-[14px] backdrop-saturate-150 backdrop-brightness-105
  shadow-[inset_0_1px_0_rgb(255_255_255/0.55),inset_0_-1px_0_rgb(255_255_255/0.16),0_18px_40px_-18px_rgb(15_12_40/0.45)]
  transition-[transform,box-shadow] duration-[260ms] ease-[cubic-bezier(0.34,1.56,0.64,1)]
  active:scale-[0.962] active:duration-100">
  Start free trial
</button>

Tailwind v4 parses the arbitrary values above as written. If your build strips them, check that the file is inside the @source path of the stylesheet that compiles the utilities — a class generated only at runtime will never exist in the CSS.

Keep the ::before highlight and the ::after gradient border in a small component stylesheet. Mixing them into utility classes makes the markup unreadable and gains nothing.

React component

The component keeps the visual in CSS and uses React only for pointer tracking.

import { useRef } from "react";

export function GlassButton({
  children,
  variant = "default",
}: {
  children: React.ReactNode;
  variant?: "default" | "strong" | "quiet";
}) {
  const ref = useRef<HTMLButtonElement>(null);

  function track(event: React.PointerEvent<HTMLButtonElement>) {
    const el = ref.current;
    if (!el) return;
    const rect = el.getBoundingClientRect();
    el.style.setProperty("--mx", `${((event.clientX - rect.left) / rect.width) * 100}%`);
    el.style.setProperty("--my", `${((event.clientY - rect.top) / rect.height) * 100}%`);
  }

  return (
    <button
      ref={ref}
      type="button"
      onPointerMove={track}
      onPointerLeave={() => {
        ref.current?.style.removeProperty("--mx");
        ref.current?.style.removeProperty("--my");
      }}
      className={`glass glass-${variant} rounded-2xl px-6 py-3.5 text-sm font-medium`}
    >
      {children}
    </button>
  );
}

No state, no useEffect, no re-render per pointer move. The pressed state stays in CSS so it works during fast clicks that React batching can miss.

Where it breaks

Nested blur. Glass on glass multiplies the backdrop filter cost and usually looks muddy. One glass layer per composition; the second layer should be a solid translucent fill.

Scrolling. backdrop-filter repaints while the background moves. Keep the number of glass elements on screen low — three or four is fine, a grid of twenty is not. Add contain: paint to the button if the page still stutters.

Contrast. White text on glass over a bright image will fail contrast on some scroll positions. Either fix the scene or use dark text with a light glass fill; do not rely on the blur to save you.

Reduced transparency. People who enable it get solid surfaces. Ship it:

@media (prefers-reduced-transparency: reduce) {
  .glass {
    background: rgb(250 250 250 / 0.96);
    backdrop-filter: none;
  }
}

Forced colors. In Windows high-contrast mode, translucent fills disappear. A border in CanvasText keeps the button visible:

@media (forced-colors: active) {
  .glass { border: 1px solid CanvasText; }
}

Focus. :focus-visible needs a real ring outside the glass — an inset glow disappears against the specular edge. Use a 2px outline with 3px offset.

The prompt that reproduces it

Build a liquid glass button with three layers.

1. Fill: linear-gradient 150deg, white 42% to 12% opacity.
   backdrop-filter blur(14px) saturate(180%) brightness(1.08).
2. Edge: 1px border white/45. Inset 0 1px white/55, inset 0 -1px
   white/16, plus a 0 18px 40px -18px contact shadow.
   A ::before radial highlight follows the pointer via --mx/--my.
3. Press: scale(0.962), drop the contact shadow, 90ms.
   Release: 260ms cubic-bezier(0.34, 1.56, 0.64, 1).

Constraints: works over a colored scene, not a flat background.
Focus-visible: 2px outline, 3px offset. Dark mode uses the same
white tints. Add prefers-reduced-transparency and forced-colors
fallbacks. No keyframes, no JS animation loop.

That last line is the one to keep. Every layer above is a static style plus a pointer variable; there is no animation loop to optimise or to leak.

If you want the same glass with motion — a dock that stretches under the hand — the liquid glass dock study is the material version with the physics written out. For scenes that need depth behind the glass, the 3D hero prompt covers the budget side.