On this page
Liquid glass is frosted glass with a sense of material: it has thickness, its edges catch the light, and it moves like something you could pick up. You can build it in React with CSS you already know, plus a little Motion for the parts that follow the pointer. This guide takes apart MotionKit's Liquid Glass Panel layer by layer, and covers the details that keep it readable and fast.
Frosted glass and liquid glass
Glassmorphism, the trend from a few years ago, is mostly a blurred, semi-transparent background. Liquid glass adds three things on top: a sense of depth from light and shadow inside the edges, a bright rim that turns to face the light, and motion that gives the surface weight. None of them needs WebGL. They are layers of gradients, shadows and masks stacked inside one rounded box.
Start with the backdrop
The glass itself is backdrop-filter, which filters whatever sits behind the element. A little blur softens the background, extra saturation keeps its colours rich through the glass, and a touch of brightness lifts it so it reads as a lighter material. Keep the Safari prefix: it still needs -webkit-backdrop-filter.
const glass = "blur(1.5px) saturate(160%) brightness(1.08)";
<div className="relative isolate overflow-hidden rounded-[28px]"
style={{ background: "linear-gradient(145deg, rgb(255 255 255 / 0.3), rgb(255 255 255 / 0.14) 48%, rgb(159 216 220 / 0.17))" }}>
<div aria-hidden className="absolute inset-0 -z-10"
style={{ borderRadius: "inherit", backdropFilter: glass, WebkitBackdropFilter: glass }} />
{children}
</div>Less blur than you'd expect looks more like glass. Heavy blur turns it into frosted plastic; a pixel or two lets the shapes behind it show through while still separating them from the content on top.
Give it thickness
Real glass is bright along its top edge and slightly darker at the bottom, where light leaves it. Stacked inset shadows fake that: a thin bright line at the top, a faint one at the bottom, a hairline all round, and two soft washes for the body.
box-shadow:
inset 0 1px 1px rgb(255 255 255 / 0.55),
inset 0 -1px 1px rgb(255 255 255 / 0.15),
inset 0 0 0 1px rgb(255 255 255 / 0.14),
inset 0 -18px 30px -18px rgb(0 0 0 / 0.12),
inset 0 16px 26px -20px rgb(255 255 255 / 0.4);A rim that catches the light
The detail that sells it is the rim: a thin ring that is brightest on the side facing the light. Draw it with a conic gradient on an element the same size as the glass, then mask away everything but a 1.5px border. Turning the gradient's starting angle towards the pointer makes the highlight follow it around the edge.
const angle = useTransform(() => Math.atan2(y.get() - 0.5, x.get() - 0.5) * 180 / Math.PI + 90);
const rim = useMotionTemplate`conic-gradient(from ${useTransform(angle, (a) => a - 60)}deg,
transparent, rgb(255 255 255 / 0.95) 60deg, transparent 120deg,
transparent 180deg, rgb(255 255 255 / 0.35) 240deg, transparent 300deg)`;
<motion.div aria-hidden className="pointer-events-none absolute inset-0" style={{
borderRadius: "inherit", padding: 1.5, background: rim,
WebkitMask: "linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)",
WebkitMaskComposite: "xor", maskComposite: "exclude",
}} />Here x and y are the pointer's position across the glass from 0 to 1, passed through springs so the light glides rather than jumps. A second, softer highlight a half turn away reads as light reflected from the far side.
A sheen and a little parallax
Two more touches make it feel liquid. A broad radial gradient centred on the pointer brightens the glass where the light is. And moving the content a few pixels against the pointer gives a sense that it sits inside the glass rather than printed on it.
- Keep the sheen subtle: white at about 20% opacity, fading out within half the panel.
- Limit the parallax to about 5px each way, or text starts to feel loose.
- Reset both to a resting position when the pointer leaves, so the glass looks lit from above by default.
Why not an SVG displacement filter?
Real refraction, where the background bends at the edges, is usually done with an SVG feDisplacementMap applied through backdrop-filter: url(#filter). It looks wonderful in screenshots, but only Chromium browsers apply SVG filters as a backdrop, and while the element is being transformed or animated it can flash opaque. For a panel people drag and squash, a native blur is the stable choice.
If you want true refraction, do it where you control the pixels: render the background in WebGL and bend it in a shader. MotionKit's Glass Ribbons, Glass Blobs and Glass Form work that way.
Keep the text readable
Glass is only useful if what's on it can be read. Check contrast against the brightest part of the background that can pass behind the panel, not an average, and raise the panel's tint until body text clears 4.5:1 there. Then respect people's settings: with reduced motion, drop the squash, the parallax and the moving highlight and keep the still glass; and where browsers support prefers-reduced-transparency, swap the backdrop for a solid tinted fill.
@media (prefers-reduced-transparency: reduce) {
.glass { backdrop-filter: none; background: rgb(28 34 40 / 0.94); }
}Keep it fast
- A backdrop filter redraws whenever what's behind it changes, so a few panels over a moving background is fine and dozens is not.
- Animate transforms and opacity, never the blur radius itself.
- Keep shadows and the caustic glow outside the element with the backdrop filter, so they don't enlarge the area being filtered.
- Let springs settle: once the pointer leaves, nothing should keep animating.