Skip to content
UIGlass

Tutorials

Liquid Glass with Tailwind CSS v4: Utilities, Custom Variant and Real Refraction

Build liquid glass in Tailwind CSS v4 with built-in backdrop utilities, a custom refract variant, two small @utility rules for the rim and the lens, and accessible fallbacks. Tested with Tailwind 4.3.

·6 min read·Tutorials

In short: Tailwind CSS covers frosted glass with backdrop-blur, backdrop-saturate and opacity modifiers like bg-white/10. For real liquid glass, add one SVG filter, a custom refract variant and a small glass-lens utility that applies backdrop-filter: url() in Chromium browsers.

Tailwind already ships most of what frosted glass needs: backdrop-blur-*, backdrop-saturate-* and opacity modifiers like bg-white/10. What it doesn’t have is the part that makes glass liquid: the lens that bends the background at the edges. That takes one SVG filter and a few lines of Tailwind v4 configuration.

This guide shows the whole setup: utilities for the frosted base, a custom variant that turns refraction on only in browsers that render it, two @utility rules for the rim and the lens, and a glass button with every interaction state. We compiled and tested it with Tailwind CSS 4.3 in Chromium.

Which Tailwind utilities do the work

Glass layerTailwind utilitiesGenerated CSS
Frostbackdrop-blur-sm / -md / -lgbackdrop-filter: blur(8px / 12px / 16px)
Colour richnessbackdrop-saturate-150saturate(1.5)
Tintbg-white/10, bg-black/20Semi-transparent background
Depthshadow-[inset_0_1px_0_…]Inset highlights and drop shadow
Shaperounded-[28px], rounded-fullborder-radius
Rim lightcustom glass-rim utilityMasked gradient ring on ::before
Lenscustom glass-lens utilitybackdrop-filter: url(#lens) …

The blur scale in Tailwind v4 is xs 4px, sm 8px, md 12px, lg 16px, xl 24px, 2xl 40px and 3xl 64px. For liquid glass stay between sm and lg. Anything above that is classic glassmorphism, and the bending becomes invisible.

Step 1: add the variant and utilities

Put this in your main CSS file. Tailwind v4 is configured in CSS, so there’s no tailwind.config.js to edit:

@import "tailwindcss";

/* refraction only where the browser renders it (class set on <html>) */
@custom-variant refract (&:where(.lg-refract *));
@custom-variant reduce-transparency (@media (prefers-reduced-transparency: reduce));

/* the specular rim: a gradient ring cut out with a mask */
@utility glass-rim {
  &::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1.5px;
    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;
  }
}

/* the lens: SVG displacement inside backdrop-filter */
@utility glass-lens {
  -webkit-backdrop-filter: url(#lens) blur(2px) saturate(160%);
  backdrop-filter: url(#lens) blur(2px) saturate(160%);
  @media (prefers-reduced-transparency: reduce) {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
  • @custom-variant refract creates a refract: prefix that only applies inside <html class="lg-refract">. Wrapping it in :where() keeps specificity at zero, so it behaves like any other variant.
  • glass-rim draws the light catching the bevel. The angle 135deg sets where the light comes from: keep it the same on every component.
  • glass-lens swaps the heavy blur for refraction plus a light 2px blur. The media query inside it switches refraction off for users who asked their system for less transparency.

Step 2: the SVG filter and detection

Add the filter once in your layout, for example right after <body>. It contains the edge displacement map explained in the liquid glass CSS guide:

<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>

Then add the class that enables the refract: variant. Only Chromium-based browsers render SVG filters inside backdrop-filter, so we detect them:

<script>
  if (navigator.userAgentData?.brands?.some(b => b.brand === 'Chromium')) {
    document.documentElement.classList.add('lg-refract');
  }
</script>

Step 3: a liquid glass card

<div class="relative isolate w-full max-w-[340px] rounded-[28px] p-7 text-white
            bg-white/10 backdrop-blur-md backdrop-saturate-150 glass-rim
            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)]
            refract:glass-lens reduce-transparency:bg-gray-900/90">
  <h2 class="mb-1 text-xl font-semibold">Liquid glass</h2>
  <p class="text-white/85">Tailwind utilities + one SVG filter.</p>
</div>

In Chrome and Edge the background bends at the rim of the card and the centre stays clear. In Safari and Firefox the same markup renders as a polished frosted card, because refract:glass-lens never applies there.

Step 4: a liquid glass button with all states

<button class="relative isolate mt-6 min-h-12 rounded-full px-7 font-semibold text-white
               bg-white/15 backdrop-blur-sm backdrop-saturate-150 glass-rim
               shadow-[inset_0_1px_0_rgb(255_255_255/.6),0_6px_18px_rgb(0_0_0/.22)]
               transition duration-300 ease-[cubic-bezier(.34,1.56,.64,1)]
               hover:-translate-y-0.5 hover:scale-[1.03] hover:bg-white/20
               active:scale-[.97] active:duration-100
               focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-white
               motion-reduce:transition-none motion-reduce:hover:transform-none
               refract:glass-lens">Get started</button>
UtilityPurpose
ease-[cubic-bezier(.34,1.56,.64,1)]Springy overshoot, so the glass feels physical
hover:-translate-y-0.5 hover:scale-[1.03]The glass lifts toward the light
active:scale-[.97] active:duration-100A quick, satisfying press
focus-visible:outline-*A clear keyboard focus ring (never remove it)
motion-reduce:*No movement for people who asked for reduced motion
min-h-1248px touch target

For the reasoning behind each state, see the liquid glass button tutorial.

Extracting a reusable component

Long class lists are fine in a component, but repeating them everywhere isn’t. Two options:

  • In React, Vue or Svelte: wrap the markup in a component and pass className through. The React guide shows how to give each instance its own filter id.
  • In plain HTML or a CMS: make a @utility glass-card { … } in CSS with the same declarations, and use one class.

Light backgrounds

On white or pastel pages the default white tint disappears. Flip the scheme:

<div class="… bg-white/60 text-slate-900 backdrop-blur-md backdrop-saturate-150
            shadow-[inset_0_1px_0_rgb(255_255_255/.9),0_10px_30px_rgb(15_23_42/.12)]">

Always check text contrast against the busiest part of the background. The accessible glass UI guide explains how.

Tailwind plugins for glass

If you’d rather install something, tw-glass is a Tailwind v4 plugin that adds glass, glass-surface, glass-strength-* and glass-chromatic-* classes built on the same SVG-in-backdrop-filter technique. It inherits the same browser limits: refraction renders in Chromium, not in Safari or Firefox. The approach in this article has no dependency and lets you shape the displacement map yourself.

Frequently asked questions

Does Tailwind have a liquid glass utility?

Not built in. Tailwind provides backdrop-blur-*, backdrop-saturate-* and opacity modifiers for frosted glass. Refraction needs an SVG filter referenced from backdrop-filter: url(), which you add with a small @utility rule.

How do I use backdrop-filter url() in Tailwind?

Use an arbitrary property such as [backdrop-filter:url(#lens)_blur(2px)], or better, define @utility glass-lens in your CSS as shown above, so you can add the -webkit- prefix and a reduced-transparency fallback.

Does this work with Tailwind v3?

The utilities do. v3 doesn’t support @custom-variant and @utility in CSS. Use addVariant and addUtilities in a plugin in tailwind.config.js, or plain CSS for the two custom rules.

Why does the glass look grey and dull?

Usually too much blur and no saturation. Use backdrop-blur-sm to backdrop-blur-md with backdrop-saturate-150, and make sure there’s something colourful behind the glass.

Can I generate Tailwind liquid glass classes automatically?

Yes. The UIGlass builder exports Tailwind classes alongside CSS, HTML, React and Vue, including the refraction filter.

What is the best backdrop blur for liquid glass in Tailwind?

Use backdrop-blur-sm (8px) to backdrop-blur-md (12px) with backdrop-saturate-150. Larger blurs hide the refraction and turn the effect into classic glassmorphism.

How do I add a glass border in Tailwind?

Make a small @utility glass-rim that draws a gradient ring on ::before with a mask, as shown above. A plain border-white/30 also works for simple glassmorphism.

Is there a Tailwind plugin for liquid glass?

Yes. tw-glass is a Tailwind v4 plugin with glass, glass-surface, glass-strength-* and glass-chromatic-* classes. It has the same browser limits as any SVG-based approach.

How do I support reduced transparency in Tailwind?

Define a custom variant such as @custom-variant reduce-transparency (@media (prefers-reduced-transparency: reduce)); and use it to switch to a solid background, for example reduce-transparency:bg-gray-900/90.

Keep reading