Top
Best
New

Posted by Sateeshm 4 days ago

Liquid Glass in the Browser: Refraction with CSS and SVG(kube.io)
488 points | 120 comments
explosion-s 4 days ago|
I made something similar to this with WebGL shaders (the benefit being it works across browsers): https://real-glass.vercel.app - The tricky thing for me was making it refract real HTML elements behind
kubeio 4 days ago||
I considered WebGL, and I agree—a shader is more performant for real-time effects.

But WebGL comes with drawbacks:

- You need JS code running before anything shows up.

- Shaders can’t directly manipulate the DOM render. To make refraction work, you’d have to re-render everything into a canvas—which isn’t really “the web” anymore.

With the SVG/CSS approach, you can pre-render the displacement map (at build time or on the backend) and get the refraction visible on the very first frame. Plus, it integrates cleanly with existing, traditional UIs.

That said, this approach could definitely be improved. Ideally we’d have shader-like features in the SVG Filter spec (there was a proposal, but it seems abandoned). There are some matrix operations available in SVG Filters, but they’re limited—and for my first blog post I wanted to focus more on pedagogy, art, and technique than heavy optimization.

kkkqkqkqkqlqlql 4 days ago||
I'm on mobile and your site works much better than the WebGL one.
Lorin 4 days ago|||
What is causing the ghosting/delay when moving the glass over text?
kaptainscarlet 4 days ago||
probably shaders are compiling and initialising on every drag movement
cycomanic 4 days ago|||
Cool this looks like it even has dispersion, i.e. colors separate at the edge of the glass element.
lagrange77 4 days ago||
https://en.wikipedia.org/wiki/Chromatic_aberration

?

cycomanic 3 days ago||
Yes chromatic abberation is caused by dispersion.
lagrange77 3 days ago||
Damn, outnerded.
IshKebab 4 days ago|||
Looks nice! It's too slow to actually use though. Op's is much smoother.
qzio 4 days ago|||
It's the opposite on my macbook pro/chrome computer... the OP is unusable, but the webGL version is super smooth
kaptainscarlet 4 days ago||
it's extremely quick on my M3 Mac too.
thisOtterBeGood 4 days ago|||
Not over here. As far as I understand Op's solution does not utilize a gpu.
freehorse 4 days ago||
I actually see gpu utilisation in OP's website when I move things (m3 pro), but this other solution shows much less gpu utilisation (prob more efficient?).
davidmurdoch 4 days ago||
Impressive!
msy 4 days ago||
Impressive but also impressive in that scrolling down through the examples makes my fully-loaded M4-Max Macbook Pro judder. I hate to imaging the performance of a full UI leveraging this stuff. Apple can do it in the UI because they can optimize the hell out of it.
kubeio 4 days ago||
Haha, I’m the author of the post.

I planned to fix the performance issues before posting here (since I knew HN would be quick to point that out), but somebody posted it first. You’re absolutely right — it’s pretty slow right now and needs optimization.

And it’s not just the refraction/displacement map: plenty of other parts, like visualisations, aren’t optimized yet either.

keepamovin 4 days ago|||
lol this demo is SO cool. you have NOTHING to be anything but proud and happy of. you did excellently and this UI is the perfect realization of this idea. Well done!

It ran perfectly smoothly with no perf hit in 2020 mba m1. there are no issues with this.

jonahx 4 days ago||||
Performance aside, this is really well done.
rafark 3 days ago|||
> You’re absolutely right — it’s pretty slow right now and needs optimization.

Man the ptsd that AIs have given us from sentences like this.

kubeio 4 days ago|||
I did a quick performance fix, should be a bit better, at least on Chrome.

(Safari stills seems to be a bit slow to render SVGs)

Anyway, I did not expect this blog post to be on HN, so still things to improve on it.

crent 4 days ago||
It's very very smooth for me now. Impressive. Thank you for sharing!
StrangeDoctor 4 days ago|||
Yeah this site does not scroll like butter as it were.

But I don’t think css can leverage the gpu in most (any?) cases. Apple has almost certainly baked something into the silicon to help handle the ui.

CognitiveLens 4 days ago||
Most browsers will engage the GPU for compositing layers if they think the layers can be separated - https://www.smashingmagazine.com/2016/12/gpu-animation-doing...
StrangeDoctor 4 days ago||
Interesting, thank you!
spicybright 4 days ago|||
Same, very laggy on my machine. The spectacular border effects also didn't work for me.
_ZeD_ 4 days ago||

  Chrome‑only demo
  The interactive demo at the end currently works in Chrome only (due to SVG filters as backdrop‑filter).
  You can still read the article and interact with the inline simulations in other browsers.
Dishonor on your WHOLE FAMILY! dishonor on you, dishonor on your cow...
Kiro 4 days ago||
This is exactly the kind of thing where this is OK since it's literally impossible otherwise. It's showcasing a specific feature that is not generally available.
sudarshandodiya 4 days ago||
In that case it would be more apt to title the post as "Liquid Glass in Chromium Browsers...", or something along those lines. People looking at the title are going to assume that it works accross all browsers, click on the link, and then get disappointed.
dmix 4 days ago||
Plenty of people have multiple browsers installed. If you have time to comment to complain then you have time to open a second app to see a tech demo
conradfr 4 days ago|||
What is funny is that for me the page on Chrome is slower and the scrolling jankier than on Firefox with the unsupported effects (macOS M1).

Besides that, very impressed by the article presentation.

chrisldgk 4 days ago||
I mean that makes sense though, right? Since it’s only available on Chrome, it’s the only one doing all the computations (GPU or otherwise) that other browsers won’t do, since they just ignore the rule.
ivolimmen 4 days ago|||
I had the same reaction but the weird thing is: it looked ok in FireFox..?
nine_k 4 days ago|||
Not OK on mobile Firefox: displacement maps do not apply, so there's no actual refraction, the liquid feeling; there's only the specular effect at the edges. Try opening it in a Chromium-based browser and compare.
yreg 4 days ago||||
Yeah, curious. The mentioned backdrop-filter seems to be supported everywhere

https://caniuse.com/?search=backdrop-filter

Cu3PO42 4 days ago||
backdrop-filter is supported by all major browsers, but specifically using SVG filters, which are more powerful and is out-of-spec, is only supported in Chromium-based browsers.
freehorse 4 days ago|||
Not sure if this is relevant, but while moving the slider around, in chromium i see 40% gpu utilisation, while in firefox less than 20% (macbook m3 pro). I do not observe any noticeable difference otherwise in terms of quality.

PS Neat website and explanations, but talking about the liquid glass as a design principle in general, I would rather ui elements in a random website not use that much of gpu for not great reasons but maybe that's my problem of not thinking different.

bfgeek 4 days ago|||
> which are more powerful and is out-of-spec

These are in the specification here: https://drafts.fxtf.org/filter-effects-1/#typedef-filter-url

And used by backdrop-filter here: https://drafts.fxtf.org/filter-effects-2/#BackdropFilterProp...

fuzzy2 4 days ago||||
The backdrop-filter thingy most definitely does not work in Firefox. Everything above does.

It works on Chromium-based browsers but it does not look great, probably needs some filtering.

mirekrusin 4 days ago|||
Try on chromium based browser - it's much better.
latexr 4 days ago|||
For those wondering about the reference:

https://youtu.be/GamP4chXJ2I?t=17

wltr 4 days ago||
I had some feeling I know that from somewhere, but couldn’t recall the source. Thanks.
7bit 4 days ago|||
Works fine on Firefox tho
jansan 4 days ago|||
No. It becomes apparent in the "Magnifying Glass" demo. Nothing is magnified in Firefox, while it is a really cool effect in Chrome.
pcardoso 4 days ago||||
And for me it was where it was the smoothest. But it even worked in Safari, albeit a bit slowly.
frizlab 4 days ago||||
No. The effects are not fully there on Firefox/Safari.
hyperbolablabla 4 days ago|||
Not on mobile
7bit 10 hours ago|||
Yeah on mobile
sonar_un 4 days ago|||
Ok, this was the funniest comment i've read in a while.
cpojer 4 days ago||
I forked a JS library for liquid-glass and patched it up with some positioning fixes. It's fun to use in presentations.

See https://github.com/nkzw-tech/liquid-glass

socalgal2 4 days ago|
Nice! I like yours more
diabllicseagull 4 days ago||
I guess we all knew that liquid glass design language was gonna leak into the web eventually but if I see a website drain my battery so it can distort the text I’m trying to read I won’t be staying.

The stuttering has already been pointed out here so I won’t pile on.

RestartKernel 4 days ago||
By far the most impressive browser implementation of glass I've seen. Though it doesn't seem like it'd be viable in a "real" website due to compatibility and performance.
gyomu 4 days ago||
This is cool and a nice writeup but - Liquid Glass is the totality of the design language, including elements close to one another merging together meta-balls like, the different tinting/clear modes, the controls being on a distinct layer from the content...

This is "just" a glass shader.

jansan 4 days ago|
That merging can be done with another, much simple filter and people have been doing it for years. It has been called the "Goo" filter.

Here is an implementation: https://codepen.io/lenymo/pen/pJzWVy

delta_p_delta_x 4 days ago||
Very nice, I really like the vector animations :)

One thing I'd say is to apply some anti-aliasing (MSAA, SMAA?)—even on a 4K display with a pixel density of 64.3 px/cm, the jaggies are visible, especially because of the extreme contrast of the caustics behind the dark background.

rezmason 4 days ago|
I'm not especially familiar with this, but I believe making the SVG element larger can increase its filter effects' resolution, and then using CSS transforms to scale the element's parent will return it to its original size, but with a higher resolution result. From there, additional changes to the filter effect (to incorporate a subtle blur for instance) may help it over the finish line.

Regardless, this is a great writeup for changes I wish to never see in ordinary UI.

seanw265 3 days ago||
I'm still not sold on liquid glass as a whole. It can be quite beautiful, but in the demos provided (and even in Apple's promotional materials) I think readability of UI elements suffers tremendously.

That said, I've seen many attempt to recreate the effect on web but you've outdone them all. The variety and mathematical modeling of edge shapes elevates this implementation above the rest.

If you decide to continue with this, I would love to see:

1. chromatic aberration along displaced areas

2. higher resolution in the refraction

Many people discussing performance issues but this runs like butter on my M3 Pro.

levmiseri 4 days ago|
As much as I still dislike Liquid Glass, this is insanely impressive!
maxvij 4 days ago|
Agreed!
More comments...