---
slug: liquid-glass-svg-filter
title: 'Liquid Glass on the Web with a Single SVG Filter'
date: '2026-11-25'
category: ['Craft']
tags: ['ui', 'svg', 'filters', 'webgl', 'design-engineering', 'vue']
excerpt: Aave Labs showed how they bring Liquid Glass to the web with one SVG filter. They didn't publish code, so we rebuilt it ourselves—refraction, light and a WebGL path for video—and ran into a Safari quirk that breaks the obvious approach.
---

> **Article source:** https://staging.unlimited.studio/en/blog/craft/liquid-glass-svg-filter

Since Apple introduced Liquid Glass, glass is everywhere again—but on the web it usually stops at `backdrop-filter: blur()`. Frosted glass blurs what's behind it. Real glass bends it. That bending is what makes the material feel physical, and it's exactly the part CSS doesn't give you.

Aave Labs recently wrote about [building glass for the web](https://aave.com/design/building-glass-for-the-web), and the approach surprised us with how small it is. The whole effect rests on one SVG filter primitive. They didn't release any code, so we rebuilt it in Vue to understand it: refraction, the light on the rim and a WebGL path for video. Along the way, we ran into a Safari quirk that breaks the most obvious way to build it.

## Refraction Is Just Moving Pixels

The primitive is `feDisplacementMap`. It takes two images: the content you want to distort and a map that says how far each pixel should move. For every output pixel, the filter reads the map and looks up the source at an offset:

```
x' = x + scale × (red − 0.5)
y' = y + scale × (green − 0.5)
```

A map value of 128 in red and green means "stay where you are". Anything above or below shifts the lookup in one direction or the other. So a lens is nothing more than an image that is neutral grey everywhere, except where the glass sits. Turn on "Show map" in the demo and you can see it: grey in the middle, colour only along the rim.

That also explains the most important design decision. The filter doesn't go on the glass—it goes on the content behind it. `backdrop-filter` with an SVG filter would be the natural fit, but according to Aave's comparison it only works in Chromium. Filtering the content itself works in Chromium, Safari and Firefox.

One attribute matters more than it looks: `color-interpolation-filters="sRGB"`. Without it, browsers convert the map to linear RGB first, and 128 no longer means zero.

## Drawing the Map

The map comes from the shape of the glass. For each pixel inside the pill, we compute two things: how far it is from the edge and which direction the edge faces. Within the bezel, the offset points outward and grows towards the rim. This pulls whatever sits just outside the glass into its edge—the same way a real lens squeezes its surroundings into its border. In the middle of the lens, the offset is zero and the content shows through untouched.

Aave describes a neat trick here that we adopted: a pill is symmetric on both axes, so you only need to compute the top-left quadrant. The other three are mirrored copies, with the horizontal or vertical offset flipped. That cuts the per-pixel work to a quarter. On a retina screen the map is built at twice the resolution, because a 1× map scaled up leaves visible steps along the rim. Including the light (more on that below), building it took about 1 to 8 milliseconds at 1× in our tests, and 5 to 17 at 2×. Encoding it as a PNG runs asynchronously with `toBlob`, so changing the shape never blocks the page.

## Safari Counts from Somewhere Else

Our first version placed the map with `x` and `y` on `feImage` and limited every pass to a lens-sized region. It worked perfectly in Chrome and Firefox. In WebKit, the content disappeared completely.

It took a few experiments to find out why. For an SVG filter on an HTML element, Chrome and Firefox measure filter coordinates from the element's corner. WebKit measures them from the corner of the document. The same `x="120"` lands somewhere else entirely, and a filter region of `0 0 818 320` doesn't even cover the element. On top of that, WebKit sizes the filter's reference box by the element's overflowing children, even when they're clipped.

The solution is to give the filter no coordinates at all. It sits on a copy of the content that is exactly as large as the stage. The first `feOffset` moves the part under the lens into a small box at the origin. All the work happens in that box, and a second `feOffset` puts the result back. A distance means the same in every engine, a position doesn't.

```html
<filter id="glass" primitiveUnits="userSpaceOnUse" color-interpolation-filters="sRGB" x="0" y="0" width="1" height="1">
    <!-- Work box at the origin: lens plus margin, no x or y anywhere. -->
    <feFlood width="348" height="232" flood-color="rgb(128, 128, 128)" result="neutral" />
    <feImage width="348" height="232" href="lens-map.png" preserveAspectRatio="none" result="lens" />
    <feComposite in="lens" in2="neutral" operator="over" result="map" />
    <!-- Bring the content under the lens to the origin … -->
    <feOffset in="SourceGraphic" dx="-96" dy="8" width="348" height="232" result="under-lens" />
    <feDisplacementMap in="under-lens" in2="map" scale="28" xChannelSelector="R" yChannelSelector="G" result="glass" />
    <feComposite in="glass" in2="lens" operator="in" result="clipped" />
    <!-- … and put the result back where the glass sits. -->
    <feOffset in="clipped" dx="96" dy="-8" width="818" height="320" />
</filter>
```

Dragging the glass now changes two numbers on two `feOffset`s. The map stays the same, and so does everything else. The work box also keeps every pass lens-sized, as Aave does with its highlight pass. Aave mentions two more Safari quirks we kept in mind: Safari caches filter output by ID, so every new map gets a filter with a new ID, and there's a size limit for filtered content that varies by version and platform.

We tested this in WebKit, Chrome and Firefox through Playwright. That's the same engine as Safari, but not an actual iPhone, so a final check on a real device is still on our list.

## The Rainbow at the Edge

Real glass splits light slightly by wavelength, which leaves a faint colour fringe at the rim. We imitate this with three displacement passes: red moves the full distance, green and blue a little less. A colour matrix keeps only one channel from each pass, and the three are added back together. In the middle of the lens all three passes agree, so the fringe only appears where the glass actually bends something.

## Light on the Rim

Aave lights the rim in its own filter pass, and our first version did the same. Alongside the displacement map, the same loop writes a height field: flat in the middle, falling off in a quarter circle across the bezel. `feSpecularLighting` read that height as a surface and lit it with two distant lights—a strong one from the top left and a weaker bounce from the bottom right. On a retina screen, the rim looked grainy. Every filter step stores 8 bits per channel, and where the rim flattens out, the light turns the small height steps into visible texture.

So the light moved into the same JavaScript loop. It uses the same model as `feSpecularLighting` (Blinn-Phong with the same two lights), but in floating point, and stores the result as a finished image next to the map. That works because the light depends only on the shape of the glass, not on what's behind it. The filter just adds it on top, and it's only recomputed when the shape changes. Switch off "Highlight" in the demo and the glass immediately looks flat.

## Video Needs a Second Path

According to Aave, Safari won't apply SVG filters to a playing `<video>`. Switch the demo to "Video" and the glass sits on top of our showreel instead. There, a WebGL canvas the size of the lens takes over. It uses the same map, the same formula and the same two lights: the fragment shader reads red and green as the offset and the finished highlight from blue. Outside the lens, the video simply keeps playing.

## Why Our Navigation Stays Frosted

After building it, we asked ourselves whether glass belongs on unlimited.studio. The obvious candidate is our navigation, which already floats above the page with a frosted blur. For now, it stays that way. The effect needs a copy of everything behind the glass, and that content should stay small and simple—Aave says so too. Behind a navigation, that's the whole page: case-study photography, video, our showreel—precisely the kind of content that gets expensive. And we'd rather use glass where it explains something, like a control floating above content, than as a trend sitting on top of everything.

## Final Thoughts

What we like most about this technique is how honest it is: no blur pretending to be glass, just pixels moved exactly where light would have bent them—and a single image that tells every pixel where to go.
