Skip to content
UIGlass

Tutorials

Liquid Glass CSS: The Complete Guide with Copy-Paste Code

Build the liquid glass effect with CSS and one SVG filter: a frosted base that works in every modern browser, a specular rim, real edge refraction for Chromium and safe fallbacks. Every snippet is tested and ready to paste.

·10 min read·Tutorials

In short: Liquid glass in CSS is built in four layers: a frosted base with backdrop-filter, a tint, a light rim, and an SVG displacement filter that bends the background at the edges. The first three work in every modern browser. The refraction layer works in Chromium browsers, so add it as a progressive enhancement.

Liquid glass is the look Apple introduced with iOS 26: controls that behave like thick, polished glass. Light catches the rim, and the background visibly bends at the edges instead of just going blurry. On the web you can get very close with CSS and a single SVG filter, as long as you build it in layers and know which browsers render which layer. (New to the term? Start with What is liquid glass UI?.)

This guide builds a complete liquid glass component from scratch. Every step works on its own, so you can stop at any level and still ship something that looks good and stays readable.

Short on time? The UIGlass builder generates all of the code below for buttons, cards, navigation pills and inputs, with live preview and export to CSS, HTML, React, Vue and Tailwind.

The four layers of liquid glass

Every convincing liquid glass surface is made of the same four layers. Classic glassmorphism uses only the first one, which is why it looks flat next to real liquid glass.

LayerWhat it doesCSS toolBrowser support
1. FrostSoftens and saturates what is behind the surfacebackdrop-filter: blur() saturate()All modern browsers
2. TintGives the glass its own colour and keeps text readableSemi-transparent backgroundAll browsers
3. LightRim highlight, inner glow and depth shadowsbox-shadow, ::before with a maskAll browsers
4. RefractionBends the background near the edges like a lensbackdrop-filter: url(#svg-filter)Chromium (Chrome, Edge, Opera, Brave, Samsung Internet)

Layers 1 to 3 give you a polished frosted glass that works everywhere. Layer 4 is a progressive enhancement: it turns frosted glass into liquid glass where the browser can draw it, and simply does nothing elsewhere.

Step 1: the frosted base (works everywhere)

Start with a translucent surface and a backdrop filter. saturate() matters as much as blur(): real glass makes colours behind it look richer, and without it the surface turns grey and muddy.

.glass {
  position: relative;
  isolation: isolate;
  box-sizing: border-box;
  width: min(100%, 340px);
  padding: 28px;
  border-radius: 28px;
  color: #fff;
  background: rgb(255 255 255 / .10);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  backdrop-filter: blur(12px) saturate(160%);
}

Keep the -webkit- prefix. Safari still needs it in many versions, and it costs nothing elsewhere.

Choosing blur and tint values

Background behind the glassBlurTint alphaText colour
Busy photo or video14–20px.18–.30 darkWhite
Soft gradient8–12px.08–.14 whiteWhite
Light, mostly white page10–16px.55–.75 whiteNear-black
Dark UI10–14px.06–.10 whiteWhite

The more detail behind the glass, the more blur and tint you need to keep text legible. Our guide to accessible glass UI covers contrast testing in detail.

Step 2: light — the specular rim and depth

Light is what makes glass read as a solid object rather than a hole in the page. Two techniques do almost all the work.

Inset shadows draw a bright top edge, a faint bottom edge and a soft outer drop shadow:

.glass {
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / .55),   /* top highlight */
    inset 0 -1px 0 rgb(255 255 255 / .12),  /* bottom reflection */
    0 10px 30px rgb(0 0 0 / .25);           /* lift off the page */
}

A gradient rim on a pseudo-element imitates light hitting the bevel from one corner. The mask trick cuts out the middle, so only a thin ring of gradient remains:

.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1.5px; /* rim thickness */
  background: linear-gradient(135deg,
    rgb(255 255 255 / .8),
    transparent 40% 60%,
    rgb(255 255 255 / .35));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
}

Change the 135deg angle to move the light source. Keep the angle the same on every component of a page, because glass lit from different directions looks wrong straight away.

Step 3: real refraction with an SVG filter

This is the step that turns glassmorphism into liquid glass. CSS has no “refract” function, but backdrop-filter accepts a reference to an SVG filter, and SVG has feDisplacementMap. That primitive moves every pixel by an amount read from a displacement map.

The map is a small image:

  • the red channel says how far each pixel moves horizontally,
  • the green channel says how far it moves vertically,
  • a value of 128 (50% grey) means “don’t move”.

So we paint a map that is neutral grey in the middle and turns into red and green gradients near the edges. The centre stays sharp and readable, and the rim bends the background like the curved edge of a thick lens.

The displacement map

Here is the map as readable SVG. It is two gradients (red left to right, green top to bottom) with a blurred grey rectangle on top that neutralises the centre:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 200" preserveAspectRatio="none">
  <defs>
    <linearGradient id="x">
      <stop offset="0" stop-color="rgb(64,0,0)"/>
      <stop offset="1" stop-color="rgb(191,0,0)"/>
    </linearGradient>
    <linearGradient id="y" x2="0" y2="1">
      <stop offset="0" stop-color="rgb(0,0,0)"/>
      <stop offset="1" stop-color="rgb(0,255,0)"/>
    </linearGradient>
    <filter id="b"><feGaussianBlur stdDeviation="10"/></filter>
  </defs>
  <rect width="300" height="200" rx="28" fill="url(#x)"/>
  <rect width="300" height="200" rx="28" fill="url(#y)" style="mix-blend-mode:screen"/>
  <rect x="24" y="24" width="252" height="152" rx="4" fill="rgb(128,128,128)" filter="url(#b)"/>
</svg>

The inset of the grey rectangle (24px here) controls how wide the bending band is. The blur controls how smoothly the bend fades into the flat centre.

The filter

Put the map inside an SVG filter as a data URI. The map has to be URL-encoded: < becomes %3C, > becomes %3E and # becomes %23.

<svg width="0" height="0" style="position:absolute" aria-hidden="true" focusable="false">
  <filter id="lens" x="0" y="0" width="1" height="1"
          primitiveUnits="objectBoundingBox" color-interpolation-filters="sRGB">
    <feImage x="0" y="0" width="1" height="1" preserveAspectRatio="none" result="map"
      href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 200' preserveAspectRatio='none'%3E%3Cdefs%3E%3ClinearGradient id='x'%3E%3Cstop offset='0' stop-color='rgb(64,0,0)'/%3E%3Cstop offset='1' stop-color='rgb(191,0,0)'/%3E%3C/linearGradient%3E%3ClinearGradient id='y' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='rgb(0,0,0)'/%3E%3Cstop offset='1' stop-color='rgb(0,255,0)'/%3E%3C/linearGradient%3E%3Cfilter id='b'%3E%3CfeGaussianBlur stdDeviation='10'/%3E%3C/filter%3E%3C/defs%3E%3Crect width='300' height='200' rx='28' fill='url(%23x)'/%3E%3Crect width='300' height='200' rx='28' fill='url(%23y)' style='mix-blend-mode:screen'/%3E%3Crect x='24' y='24' width='252' height='152' rx='4' fill='rgb(128,128,128)' filter='url(%23b)'/%3E%3C/svg%3E"/>
    <feDisplacementMap in="SourceGraphic" in2="map" scale="-0.18"
                       xChannelSelector="R" yChannelSelector="G"/>
  </filter>
</svg>

Three attributes do the heavy lifting:

  • primitiveUnits="objectBoundingBox" makes the map and the scale relative to the element, so one filter fits any size.
  • scale="-0.18" sets the strength. Negative values pull the background inwards, like a convex lens. Positive values push it outwards. Try values between -0.08 (subtle) and -0.3 (dramatic).
  • color-interpolation-filters="sRGB" stops the browser from converting the map to linear colour. Without it, 128 no longer means “don’t move” and the whole surface shifts.

Apply it only where it renders

At the time of writing, only Chromium-based browsers draw an SVG filter inside backdrop-filter. Safari and Firefox ignore the declaration or drop the backdrop effect entirely. So don’t put url(#lens) in your base rule. Add a class on <html> in Chromium and apply refraction under it:

<script>
  if (navigator.userAgentData?.brands?.some(b => b.brand === 'Chromium')) {
    document.documentElement.classList.add('lg-refract');
  }
</script>
.lg-refract .glass {
  -webkit-backdrop-filter: url(#lens) blur(2px) saturate(160%);
  backdrop-filter: url(#lens) blur(2px) saturate(160%);
}

Notice that the blur drops from 12px to 2px. Refraction looks best through clear glass. Heavy frost hides the bending you just worked for. The SVG refraction deep dive explains chromatic aberration and other lens shapes.

Step 4: the complete component

Here is everything together. Paste it into an empty HTML file over any colourful background:

<div class="glass">
  <h2>Liquid glass</h2>
  <p>Frosted everywhere, refracted in Chromium.</p>
</div>
.glass {
  position: relative;
  isolation: isolate;
  box-sizing: border-box;
  width: min(100%, 340px);
  padding: 28px;
  border-radius: 28px;
  color: #fff;
  background: rgb(255 255 255 / .10);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  backdrop-filter: blur(12px) saturate(160%);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / .55),
    inset 0 -1px 0 rgb(255 255 255 / .12),
    0 10px 30px rgb(0 0 0 / .25);
}
.glass::before { /* rim from step 2 */ }
.lg-refract .glass {
  -webkit-backdrop-filter: url(#lens) blur(2px) saturate(160%);
  backdrop-filter: url(#lens) blur(2px) saturate(160%);
}

Add the SVG filter from step 3 once per page, anywhere in <body>, plus the detection script in <head>. We tested this exact code in Chromium: the stripes behind the card bend at the rim and the centre stays flat and readable.

Accessibility: respect user settings

Glass puts an unpredictable background behind your text, so build in escape hatches. Operating systems expose them as media queries:

@media (prefers-reduced-transparency: reduce) {
  .glass, .lg-refract .glass {
    background: rgb(20 22 30 / .92);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
@media (prefers-contrast: more) {
  .glass { background: rgb(10 12 18 / .85); }
  .glass::before { background: #fff; }
}
@media (forced-colors: active) {
  .glass { border: 1px solid CanvasText; }
}
@media (prefers-reduced-motion: reduce) {
  .glass { transition: none; }
}

prefers-reduced-transparency doesn’t work in every browser yet. Where it isn’t supported, the rule is simply ignored, so it’s safe to add today. Always check text contrast against the busiest part of the background, not the average. WCAG asks for 4.5:1 for body text.

Performance: where liquid glass gets expensive

Backdrop filters make the browser re-render what is behind an element whenever anything under it changes. A few rules keep pages smooth:

  • Limit the area. Glass on a 48px button costs little. Glass on a full-screen panel with a large blur on a phone costs a lot.
  • Keep blur radii moderate. Cost grows with the radius. 2–16px covers almost every design.
  • Avoid stacking glass on glass. Each layer re-filters the one below.
  • Don’t animate the filter itself. Animate transform and opacity instead.
  • Test on a mid-range Android phone, not only on a desktop GPU.

The backdrop-filter performance guide explains how to measure the cost in Chrome DevTools.

Liquid glass vs glassmorphism in code

If you already have glassmorphism CSS, the upgrade path is short:

GlassmorphismLiquid glass
Background behind the surfaceBlurredBlurred lightly and bent at the edges
Typical blur16–30px0–6px (refraction needs clarity)
Edges1px white borderGradient rim lit from one direction
DepthDrop shadowInset highlights + drop shadow
Extra codeNoneOne SVG filter + one class

For the design side of the comparison, read Glassmorphism vs liquid glass.

Common problems and fixes

The refraction does nothing at all.

Check four things in order: the browser is Chromium-based, the lg-refract class is actually on <html>, the filter id matches the url(#…) reference, and the # characters in the data URI are encoded as %23. A single unencoded # silently breaks the map.

The whole surface is shifted or smeared, not just the edges.

The map’s neutral value isn’t being read as 128. Add color-interpolation-filters="sRGB" to the filter and make sure the centre rectangle is exactly rgb(128,128,128).

The bend has a hard visible step.

Increase the stdDeviation of the blur inside the map, or make the inset of the grey rectangle larger so the gradient has more room to fade.

It looks great in Chrome but flat in Safari. Is that a bug?

No, that is expected. Safari and Firefox don’t render SVG filters inside backdrop-filter, so they show the frosted layers 1–3. That’s why those layers have to look good on their own. Our Safari and Firefox guide and browser support page cover engine-by-engine behaviour, and UIGlass’s Scene mode offers a different route to refraction outside Chromium.

Can I make liquid glass with pure CSS and no SVG?

You can make excellent frosted glass with pure CSS. Real edge refraction needs a displacement filter, and on the web that means SVG. Some libraries use WebGL instead, which works in more browsers but adds JavaScript and GPU cost.

Does liquid glass hurt Core Web Vitals?

Not by itself. The SVG filter is a few kilobytes and doesn’t block rendering. The risk is runtime smoothness (Interaction to Next Paint) when large, heavily blurred areas re-render during scrolling. Keep glass on controls, not on whole pages.

Ready-made components

The same technique, shaped for specific components: buttons with every state, a floating navbar, glass cards, and versions for Tailwind, React and WordPress.

Skip the hand-tuning

Hand-writing displacement maps is a great way to understand the technique, but a slow way to design with it. In the UIGlass builder you adjust refraction, frost, tint, light angle and states with sliders, check contrast live, and export production-ready code with the Chromium detection and accessibility fallbacks already included.

What is liquid glass in CSS?

Liquid glass in CSS is a translucent surface that blurs, tints and bends the content behind it like thick glass. It combines backdrop-filter for frost with an SVG feDisplacementMap filter for edge refraction.

Which browsers support liquid glass CSS?

Every modern browser supports the frosted part with backdrop-filter. The refraction part, an SVG filter inside backdrop-filter, renders in Chromium browsers such as Chrome, Edge, Opera, Brave and Samsung Internet. Safari and Firefox show the frosted version.

How do I make liquid glass readable?

Raise the tint, add a little more blur behind long text and check contrast against the busiest part of the background. Body text needs at least 4.5:1. See the accessible glass UI guide.

Is there a liquid glass CSS generator?

Yes. The UIGlass builder generates liquid glass CSS, the SVG filter, Chromium detection and accessibility fallbacks for buttons, cards, navigation and inputs. Our generator comparison covers the alternatives.

Keep reading