Writing · 10 November 2026
Liquid Glass for the web, drawn by a shader
Apple introduced Liquid Glass at WWDC 2025: controls made of what looks like curved glass, bending and brightening whatever passes beneath them. It is a material you understand by touching it, not by reading about it.
I wanted that material on this site: in every browser, on real components, at real sizes. This is how it was built: what the effect is, how it works, the components made with it, and the unglamorous work that keeps the glass sharp once it leaves the demo.
Drag the lens. Everything else on this page is the same engine with different numbers.
Why glass is hard on the web
The effect is one idea: each pixel of the glass shows a different point of what is behind it. In the months after WWDC a wave of demos rebuilt it for the web, and most of them only ran in Chromium. They leaned on one of two things: an SVG displacement filter used as a backdrop-filter, which only Chromium accepts, or the experimental HTML-in-Canvas API, which is still behind a flag.
| Approach | Chromium | Safari | Firefox |
|---|---|---|---|
SVG backdrop-filter | |||
| HTML-in-Canvas API | Behind a flag | ||
| A WebGL2 shader (this page) |
A third way applies the same SVG filter to an element itself. That runs everywhere, but it bends the element's own content: the glass cannot float over something else and bend it.
This site takes another route. The glass is drawn by a fragment shader in WebGL2, which every current browser has. A shader is exact to a fraction of a pixel, takes any shape at any size, and can pour one shape into another.
First, a button
Here is the result before the reasons: one piece of that glass, as a button. It is the plainest thing the engine draws and the reference for everything after it. Its numbers are not tuned by eye. How far the rim bends, how much it frosts and how it lifts the colours behind it follow Apple's material as measured, size by size.
Wash a colour in and the symbol takes a little of it, as a tinted button does on iOS. Transparency runs from frosted to clear. A solid or frosted fill swaps the glass out where it would cost legibility, and the accessibility option draws the symbol and an outline in black.
It is on a rubber band, too. It swells when pressed and comes back more slowly, dipping once below its size. Hold it and pull: it ignores a finger that only wanders, then draws out toward the pull like a drop, thinning as it lengthens so that its area stays the same. Let go and it springs home.
TSX
<GlassButtonGroup
backdrop={photo}
items={[
{ id: "like", label: "Like", icon: <Heart />, onClick: like },
{ id: "add", label: "Add", icon: <Plus />, text: "Add", width: 102 },
]}
/>
// smaller buttons, tinted
<GlassButtonGroup className="h-9" tint="rgba(10, 132, 255, 0.55)" items={items} />How it works
Glass reads as glass because of two effects: light bending at the rim, and a line of light along the edge. Both can be built from first principles, and neither needs more than school physics.
Refraction
Light travels at different speeds in different materials. When a ray crosses from one into another at an angle, the change of speed turns it. How far it turns is given by Snell's law, which ties the angle on each side of the boundary to each material's refractive index:
n₁ · sin(θ₁) = n₂ · sin(θ₂)
Drag the ray and move the slider, and three things show up:
- Into a denser material the ray bends toward the normal, the line standing square to the surface. Into a thinner one it bends away.
- Bent far enough away, none of it gets through and it bounces back instead: total internal reflection.
- A ray that arrives square to the surface is never bent at all.
That last one is why the flat middle of a piece of glass shows what is under it untouched, and everything interesting happens at the edge. To keep each ray to one simple answer the scene is narrowed: the glass sits in air, each ray bends once on its way in, and rays fall straight down onto a background the glass lies flat on.
The shape of the edge
Picture a slice cut straight down through the edge of the glass: flat across the middle, curving down to nothing at the rim. That curved part is the bezel. One function describes it. It takes the distance in from the outer edge, from 0 at the rim to 1 where the flat part begins, and returns how high the glass is there.
The height itself bends nothing. What matters is the slope, because the slope sets the angle at which a falling ray meets the surface:
TypeScript
const d = 0.001
const slope = (surface(x + d) - surface(x - d)) / (2 * d)
// a ray falling straight down meets the surface at this angle to its normal
const theta1 = Math.atan(slope)
// Snell's law, air into glass
const theta2 = Math.asin(Math.sin(theta1) / ior)
// the ray leans by the difference, and keeps leaning all the way down
const shift = Math.tan(theta1 - theta2) * (height + thickness)That last number, the shift, is the whole effect: how far from straight below the ray ends up. Everything after this is bookkeeping for that one number. Four profiles cover the range:
Convex circle
Convex squircle
Concave
Lip
Here is the glass in cross-section, with one ray sweeping across it. The ray bends where it meets the surface; the arrow along the background shows how far it landed from where it was heading. Drag the ray, or pick another surface.
Convex surfaces pull rays inward, so everything the glass shows comes from underneath it. Concave ones push rays out past the edge, which is awkward: the glass then has to show something that is not under it. And two rays the same distance from the edge always shift by the same amount, which is the fact the rest of the engine is built on.
One line, reused all the way round
One line across the bezel gives a list of shifts. The whole piece of glass needs one at every point, with a direction: a vector field. The length of each vector comes from that list, by distance from the edge. The direction is always square to the edge.
So the expensive part, tracing rays, happens on a single half-slice of the glass and nowhere else. The engine traces 64 rays and lets the shader blend between neighbours. That takes well under a millisecond, so it can be redone on every tick of a slider. The shifts are stored divided by the largest one, with the largest kept beside them in pixels:
TypeScript
const max = Math.max(...shifts.map(Math.abs))
const table = shifts.map((s) => s / max)Splitting the shape of the curve from its size is what lets the effect be turned up, down or faded in by changing one number, without tracing again.
From a table to pixels
The glass is drawn by a fragment shader, a small program the graphics card runs for every pixel. It describes its shape with a signed distance function: give it a point, and it returns how far that point is from the edge and which way the edge faces. Those are exactly the two things the vector field is made of. So the 64 numbers go to the shader as they are, and each pixel does the lookup for itself:
GLSL
// d: distance to the edge (negative inside); n: which way the edge faces
float t = clamp(-d / bezel, 0., 1.) * 63.;
float shift = maxShift * mix(table[int(t)], table[min(int(t) + 1, 63)], fract(t));
vec3 colour = texture(backdrop, uv - shift * n).rgb;The other way to carry the field is as a picture, for SVG's feDisplacementMap filter. Each vector is split into x and y, and each part is written into a colour channel, with 128 meaning no movement:
TypeScript
const x = Math.cos(angle) * length // -1 to 1
const y = Math.sin(angle) * length
const pixel = { r: 128 + x * 127, g: 128 + y * 127, b: 128, a: 255 }It is a clever encoding, and worth understanding, because it shows the field for what it is. Side by side:
| Displacement map | Shader | |
|---|---|---|
| Bends the backdrop in | Chromium only | Any browser with WebGL2 |
| Can bend | Live page content | An image, video or canvas, or a flat colour |
| Precision | 256 steps a direction | Fractions of a pixel |
| Shape | One map per shape | Any rounded rectangle; shapes can merge |
| Resizing | Repaint the map | Nothing to redo |
Playground
One set of controls drives everything so far: the glass itself, the rays across its bezel, the curve of shift against distance, and, for comparison, the displacement map a filter would have needed at this size. Drag the glass about, and turn on the checkerboard to see where each square is taken from.
The rim light
Refraction is half of it. The other half is the bright line along the edge, where the curved rim catches the light. It follows the edge, and how bright it is at each point depends on how squarely that part of the edge faces the light. The side facing it glows, and so does the side opposite, where the light comes back out.
Specular angle: −60°
The shader has what it needs for this already. The distance function hands over the direction the edge faces at every pixel; the highlight is that direction compared with the light's. Both effects are lines of the same program, run on the same pixel, so they are combined from the start. How wide, how bright and from where is taste more than physics, so here it is to turn:
A family of components
A material is only worth having on things people use. So here is what else was built with it. Each is a React component, and all of them share one material: tint, transparency, fill and accessibility mean the same thing on every piece. The button in the corner of this page changes them for all the glass on it at once.
They install as source, the way a shadcn component does, and every one works with no props beyond its content. A class sets its size, as it would on any element; the bezel and the bend follow.
Terminal
npx shadcn@latest add https://rushil.is-a.dev/r/liquid-glass.jsonTSX
import { GlassSwitch, GlassProvider } from "@/components/liquid-glass"
<GlassSwitch />
<GlassSwitch className="h-10" />
// one material for everything inside: a colour, clear glass, accessibility
<GlassProvider tint="rgba(10, 132, 255, 0.55)" variant="clear">
<App />
</GlassProvider>Most of the demos below are drawn up to twice life size, so the glass can be studied. In a project the same components come out at a phone's sizes: a 28 px switch, 44 px buttons.
Switch
At rest the thumb is a plain white pill, because a control nobody is touching should be quiet. Press it and it swells into glass: a flat middle that shows the track exactly as it is, and a thin rim that pulls the track's colour out to the very edge. Pull it past the end of its travel and it stretches toward your finger.
The picker under the demo swaps the profile of the rim for any of the four surfaces from earlier. In code it keeps its own state unless you give it one:
TSX
<GlassSwitch defaultChecked onChange={setOn} />
// controlled, and larger
<GlassSwitch checked={on} onChange={setOn} className="h-10" />Slider
The same thumb on a rail. The flat middle matters more here: the level you are setting has to stay readable through the glass while the rim bends the rail either side of it. The rail itself is frosted, so a busy background never shows through it sharp.
TSX
<GlassSlider defaultValue={40} onChange={setVolume} />
<GlassSlider value={volume} min={0} max={11} step={1} onChange={setVolume} className="h-8" />Tab bar
The selected tab sits under a bubble. Tap another and the bubble lifts, flies over and sets down in about a quarter of a second, with no overshoot. Hold it and it rises into a lens standing on the bar: it enlarges the icons under it, turns them the accent colour, and gathers the bar's edge into a dark crescent along its top and bottom. Drag it and it follows your finger exactly, squashing flatter the faster it goes.
Two engines draw this. One draws the bar. The other draws the bubble, and since glass cannot see other glass, it is handed a picture of the bar under it, redrawn whenever anything moves.
TSX
<GlassTabs
items={[
{ id: "home", label: "Home", icon: <Home /> },
{ id: "search", label: "Search", icon: <Search /> },
]}
defaultValue="home"
onChange={setTab}
className="h-16"
/>Menu
A button that becomes its menu. The capsule folds to a circle, the circle is thrown outward, and the sheet arrives slightly too big and settles, its centre overshooting by about a quarter of the distance it travelled. The labels are laid out at full size from the first frame and arrive large and blurred, sharpening as the glass reaches them.
It is one piece of glass throughout. The button and the sheet are two shapes in a single distance field, which is why they pour into each other instead of cross-fading. Slow motion shows each step. The dots mark the other places the button can sit: click one to move it there, and the menu opens away from that edge.
TSX
<GlassMenu
label="Sort"
items={[
{ id: "name", label: "Name", checked: sort === "name" },
{ id: "date", label: "Date", checked: sort === "date" },
{ id: "reset", label: "Reset", separator: true },
]}
onSelect={setSort}
side="bottom"
align="end"
/>Morphing buttons
A row of buttons that changes into a different row. A pressed button swells and fuses with its neighbour; on release the glass slides to its new places, a capsule splitting in two here, a word blurring into a tick there.
You describe the row as it is now. Hide a button, change its width or its face, and the glass works out how to get there.
TSX
<GlassMorphingButtons
items={[
{ id: "more", label: "More", content: <Dots /> },
{
id: "edit",
label: editing ? "Done" : "Edit",
width: editing ? 44 : 99,
tint: editing ? "#5748ec" : undefined,
faces: { edit: "Edit", done: <Check /> },
face: editing ? "done" : "edit",
onClick: () => setEditing(!editing),
},
]}
/>None of this motion was tuned by feel. Every spring, delay and stretch in the controls above was fitted, frame by frame, to screen recordings of the real ones, then written as a share of the control's size, so it holds at any scale.
Magnifying glass
Glass that enlarges. The zoom is a single number: before anything bends, each pixel looks nearer the centre of the lens by that factor, and the rim then bends as usual. What is under it here is a note in ordinary type, the way a loupe sits over text on a phone.
TSX
<GlassCard
variant="clear"
radius={75}
backdrop={pageRef}
surface={{ profile: "squircle", bezel: 18, thickness: 86 }}
zoom={1.3}
className="h-[150px] w-[210px]"
/>Sheets, not only controls
Controls are small. The same engine draws large sheets too: several at once, in one canvas, each with its own size, tint and spring. These five are the kinds of surface a desktop is made of, at a desktop's sizes and corner radii, with content of their own.
Widgets. Three sheets of glass, each its own shape. Drag them: the glass re-reads what is under it as it moves, and turns dark by itself over the darkest parts of the wallpaper.
TSX
<div className="relative h-[420px]">
<img ref={photo} src="/wallpaper.webp" alt="" className="absolute inset-0 size-full object-cover" />
<GlassPanels
backdrop={photo}
className="absolute inset-0"
panels={[
{ id: "clock", x: 24, y: 24, w: 158, h: 158, radius: 30, content: <Clock /> },
{ id: "weather", x: 196, y: 24, w: 158, h: 158, radius: 30, content: <Weather /> },
]}
/>
</div>Control Center. Eleven modules in one distance field, drawn by one canvas. Panels that share a group are one piece of glass: they turn light or dark together. Click the item in the menu bar to close and reopen it; the capsules and round buttons toggle, and the sliders drag.
HomeView OS Home. A house in one widget, on six tiles that all work. Step the thermostat and it tells you whether it is heating or cooling. Switch on the lights, unlock the door or talk on the intercom and that tile is washed white, its words dark, the wallpaper still showing through. Arrive Home does several at once. A tile's corners are not all alike: the one that sits in a corner of the widget follows the widget's own curve, and the rest are tighter.
Notifications. A stack that opens on a click. Each note is its own piece of glass on a spring, so the stack fans out and settles instead of sliding.
Command bar. One field. It is the same frosted glass with a black tint washed in, which is what makes it smoky. Type a few letters and it completes them, then try the sliders: how far the rim bends, how much the glass frosts, and how dark the tint is.
A sheet does not have to be a rectangle at all. Flow is a watch face whose four digits are cut from a single piece of glass, over a gradient that never stops moving. Every stroke bends what drifts beneath it, and the rims catch a light that turns to follow your pointer.
Making it work everywhere
This is where most of the work went, and where a demo that works once stops being enough. Getting the same glass to draw correctly across a whole page, in every browser and at every size, meant working through a string of problems that a single lens on a single photograph never shows.
Sixteen canvases
Every piece of glass owns a WebGL canvas, and a browser allows a page about sixteen of them before it starts discarding the oldest. This page has more than twenty demos. So each one is mounted only while it is within a screen of the viewport and let go when it is far away, keeping its height so the page never shifts. Where there is no WebGL2 at all, or a context is lost anyway, a component falls back to a CSS blur and carries on.
A rim that stays smooth
A strongly curved rim squeezes a wide strip of the background into a few pixels, and only in one direction: across the rim, never along it. Read that with a single sample and a thin bright line in the background sparkles as the glass moves. Read it from a blurrier copy of the background and the rim breaks into blocks. The fix is to measure the footprint each pixel really covers and take sixteen samples along its long side, each as sharp as its short side allows.
Small glass that still bends
Ray tracing scales perfectly: halve the glass and every shift halves with it. That is the problem. On a small control the part of the rim that bends hardest is only two or three pixels wide, too few to draw a bend in. So below 64 px the engine lets the bend shrink more slowly than the glass, the way a typeface thickens its strokes at small sizes.
Sharp type under glass
The tab bubble covers the selected tab, so at first its icon and label reached the screen only through the glass: drawn to a picture, copied to a texture, sampled back. Each step softened them. Now, while the bubble rests, the tab under it is ordinary text laid over the glass, and the glass's own copy takes over only as the bubble lifts into a lens.
One number per control
Each control is drawn from a single number, its height. Its width, its bezel and its bend follow from it. That number comes from CSS: a class such as h-10 resizes a switch the way it would resize a div. The default sizes live in a cascade layer, so a utility class always wins over them.
The settings people already chose
The glass follows the system. With Reduce Motion on, nothing swells or morphs. With Reduce Transparency on, glass is frosted. With Increase Contrast on, symbols and outlines are drawn solid. Nobody has to find a setting on this page to get the version they need.
What it still cannot do
The trade named at the start is still there. A filter on the backdrop sees the real page. A shader sees what it is handed. For a photograph, a video or a canvas that costs nothing: hand it over. For ordinary page content, such as the note under the magnifier, it means keeping a hidden copy drawn into a canvas and redrawing it when the content changes, which is more to keep in step than a filter that simply looks.
The missing piece is a way for a shader to read the page behind it directly. Until browsers offer one, handing the glass a copy is the price of running everywhere, and for controls over images and video it is a price worth paying.
Thanks
None of this would have been possible without kube. His article, Liquid Glass in the Browser: Refraction with CSS and SVG, is where the idea at the centre of this page comes from: trace light through the edge of a piece of glass once, and turn the result into a field that bends every pixel. The section on how the glass works follows his explanation step by step, and several of the demos began as his. If you enjoyed this, read his next.