Skip to content

Frosted Glass in CSS: How backdrop-filter Works

What you'll learn: Understand the four properties that create frosted glass, why backdrop-filter needs a busy background to be visible, and how to keep text on glass readable.

Frosted glass is four properties, not one

A glass surface in CSS is built from four cooperating pieces: a translucent fill, a backdrop blur, a hairline border that catches the light, and one soft shadow that makes the element float. The catalog's classic Glass Button uses each piece: `background: rgba(255, 255, 255, 0.2)` for the fill, `backdrop-filter: blur(20px)` for the frost, `border: 1px solid rgba(255, 255, 255, 0.3)` for the edge highlight, and `box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2)` for depth.

The order matters for tuning. The blur radius controls how much the background is dissolved; the fill alpha controls how much of the result you can see through. Raise the blur without lowering the alpha and the surface reads as fog; lower the alpha without raising the border opacity and the edges disappear.

Glass ButtonFull component →
Complete HTML + CSS
.glass-container {
  position: relative;
  padding: 2rem;
  border-radius: 1rem;
  background: linear-gradient(135deg, #667eea, #764ba2, #f093fb);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.glass-bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.6;
}

.glass-bg-orb-1 {
  top: 1rem;
  left: 1rem;
  width: 5rem;
  height: 5rem;
  background: #fbbf24;
}

.glass-bg-orb-2 {
  bottom: 1rem;
  right: 1rem;
  width: 6rem;
  height: 6rem;
  background: #22d3ee;
}

.glass-button {
  position: relative;
  padding: 1rem 2rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.glass-button:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
  box-shadow: 0 8px 32px rgba(168, 85, 247, 0.2);
}

.glass-button:focus {
  outline: 2px solid rgba(168, 85, 247, 0.5);
  outline-offset: 2px;
}

<div class="glass-container">
  <div class="glass-bg-orb glass-bg-orb-1"></div>
  <div class="glass-bg-orb glass-bg-orb-2"></div>
  <button class="glass-button">Glass Button</button>
</div>

backdrop-filter samples what is behind the element

The most common glassmorphism bug is a glass element on an empty background: the blur has nothing meaningful to sample, so the button looks like a flat translucent rectangle. The Button demo avoids this deliberately — it sits inside a container with a saturated diagonal gradient and two blurred color orbs (`filter: blur(40px)`, `opacity: 0.6`) positioned behind the button. The glass does not blur those orbs directly; it samples the already-composited container, so the orbs bleed through as soft color fields.

When you reuse this pattern on a real page, make sure something visually interesting sits under the glass: a gradient, an image, or color blobs. If the page background is flat white, prefer a solid surface with a subtle shadow instead — the glass effect adds cost without a visible payoff.

Ship both filter declarations

The examples in the catalog always pair the standard property with the prefixed one: `backdrop-filter: blur(20px)` followed by `-webkit-backdrop-filter: blur(20px)`. Safari required the prefixed form until version 18 (2024); omitting the prefix makes the frosted effect silently fall back to a plain translucent fill for those visitors. Keep both lines when you copy the code.

One more support nuance is recorded in the Aurora example's accessibility notes: glass surfaces need a fallback plan. You cannot detect support with a plain CSS selector, but you can design the fill alpha so the surface still reads as a button without blur — that is exactly why these buttons combine translucency with a visible border and shadow instead of relying on the blur alone.

Aurora Glass ButtonFull component →
Complete HTML + CSS
.aurora-glass-btn {
  padding: 1rem 2rem;
  border-radius: 0.75rem;
  font-weight: 600;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(236,72,153,0.1), rgba(6,182,212,0.1));
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.12);
  cursor: pointer;
  animation: aurora-shift 8s ease-in-out infinite;
  transition: all 0.3s ease;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.08);
}
.aurora-glass-btn:hover { transform: scale(1.03); box-shadow: 0 12px 40px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.12); }
.aurora-glass-btn:active { transform: scale(0.96); }
@keyframes aurora-shift { 0% { background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(236,72,153,0.1), rgba(6,182,212,0.1)); } 33% { background: linear-gradient(135deg, rgba(6,182,212,0.15), rgba(99,102,241,0.1), rgba(236,72,153,0.1)); } 66% { background: linear-gradient(135deg, rgba(236,72,153,0.15), rgba(6,182,212,0.1), rgba(99,102,241,0.1)); } }

<button class="aurora-glass-btn">Aurora</button>

Animate the glass, not the blur

The Aurora button's gentle color drift comes from a keyframe animation that swaps three low-alpha gradients over eight seconds — the backdrop filter itself is never animated. That is the performance-safe shape for glass motion: a `backdrop-filter` surface is composited every frame, so animating the blur radius or combining it with continuous transforms forces the browser to re-sample the backdrop repeatedly. Prefer animating only cheap, compositor-friendly properties on glass, and keep the blurred area small.

The Apple-style example adds a moving highlight with a pseudo-element that sweeps across the button (`glass-shine`). It is a nice trick, but note what it animates: `left` from -100% to 100% is a layout-ish property that triggers paint on every frame. If you need the same shine at larger sizes, doing it with a `translateX` transform on the pseudo-element moves the work to the compositor.

Apple Liquid GlassFull component →
Complete HTML + CSS
.apple-glass-button {
  position: relative;
  padding: 1rem 2rem;
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: white;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.apple-glass-button:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(1.03);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 0 20px rgba(168, 85, 247, 0.2);
}

.apple-glass-button:active {
  transform: scale(0.97);
}

.apple-glass-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent);
  animation: glass-shine 3s linear infinite;
}

@keyframes glass-shine {
  0% { left: -100%; }
  100% { left: 100%; }
}

<button class="apple-glass-button">Apple Glass</button>

Keep text readable over frost

The catalog's accessibility notes for all three buttons repeat the same rule: text on glass must still meet the 4.5:1 contrast ratio, because the background can change under it. The practical technique is to push the fill toward the side of the text — a darker glass for white text — or to add a subtle inner scrim behind the label. Test with a light and a dark backdrop; a glass button that only works over one background is a broken button.

If the component is icon-only, keep an `aria-label` on it and preserve the 44×44px minimum touch target regardless of how small the glass surface looks visually.

Where to go next