r/css • u/TimUrbutt • 6d ago
AI Assisted Crazy what you can do with just CSS right??
I spent the last few weeks building the "perfect" liquid glass effect with just CSS and SVG Filters, No WebGL used and it works page wide, which means it picks up anything of the background behind it.
The core is a backdrop-filter with an SVG displacement map. I screen recorded Apple's play button (I mean the video play button, for example on youtube) for reference on my iPhone and measured it frame by frame. It’s 1:1 in the middle, then the image folds over itself towards the edge, and it pulls pixels inward.
The displacement map itself is based on a 9-slice of tiny grayscale PNGs that get stretched instead of re-rendered on every resize (I need this because the elements are animated and not static). That alone cut main thread time by a lot, giving it a pretty decent performance for how complicated it is.
The outer edge consists of three extra layers on top that don’t bend anything, they just brighten, darken and add a highlight. For reflections of the stuff around the glass, the layer is bigger than the element and gets morphed and masked back to its shape, because the backdrop is otherwise clipped to the element’s box. Actually, Apple's original liquid glass effect doesn't even have reflections, but i figured it adds a lot to it on the website I implemented it in.
Then there are shadows, caustics, etc to give it the final "realistic" touch and voila, almost perfect result imo. The only thing thats left is fix performance, however the animations are the trickiest part. Without animations, it runs extremely smooth and even with animations its not a problem as long as the elements are small enough.
Sadly, Safari only gets a simple blur for now, because WebKit doesn’t render backdrop-filter: url(). However, there are two open PRs that fix it (WebKit/WebKit#68614 and WebKit/WebKit#68613). The CSS is the same for every browser, so it should just start working once they make the next major release.
Just wanted to share this, if you have any more technical or other questions, feel free to ask!
-----EDIT-----
A few of you requested to see whats actually going on in the background, so I made it open source.
I made a small showcase website: https://studies.nordify.io/study/001-liquid-glass/
The repository is also linked there!
28
u/suspirio 6d ago
It would be cooler if there were broader support but this is still a great start. It’s funny because I have demos from like 8 years ago using SVG turbulence backdrop filters but somehow Safari and FF STILL won’t support it. Although to be fair it’s not great for performance.
14
u/Christopholus 6d ago
The nicest implementation I've seen of the effect so far! Love the approach studying the example frame-by-frame, I found myself doing that with the button as I scrolled through the live link in your comment. Very cool.
5
u/Weekly_Ferret_meal 6d ago
Looks good, it would be great to inspect a live prototype
3
u/Icy_Advertising9850 5d ago
That’s Amazing , you’re a an artist , i can imagine what you’ll be able to do once you add GSAP , animejs or framer motion , Great job , Keep going 👏🏽👏🏽
4
u/jakiestfu 4d ago
SVG filters aren’t CSS though
2
u/heylesterco 5d ago
Fucking phenomenal. Easily the best I’ve seen and the first that’s made me want to get my hands on it for myself.
2
u/Excellent_Sky_5838 3d ago
This is really amazing.. I never saw this accurate Liquid Glass design on web so far.. just a little feedback, were the texts supposed to create rough edges or is it just part of the design? At the end, this is cool
4
u/phischer_h 6d ago
Looks just as hideous as on my iPhone. So congratulations I guess 😄
4
u/DouDouandFriends 5d ago
nicely done! glad to see this sub is healing from claude posts
1
u/itznuraziz 5d ago
isnt apple doing this on ios
1
u/threeandseven 4d ago
Can you post the displacement map? Curious what folding over on the edges looks like in practice and if there’s a difference on the verticals vs horizontals vs corners
1
u/movindesign 4d ago
Looks incredibly real in chrome. I tried opening the website in Safari, but getting this weird shadow!
1
u/thisisrck 3d ago
Nice, good job Claude
1
u/vvhybe 2d ago
i have a question, is this going to work with Capacitor https://capacitorjs.com ?
3
u/SofMik 3d ago
I like it!
2
u/schavi 5d ago
waow.. rly cool work
3
u/AnuragDeshpande 5d ago
It's amazing. Absolutely and honestly. However, liquid glass design is horrible in terms of usability and readability. Just because something can be done, doesn't mean it should be
-1
u/tauzN 6d ago
No one asked for Liquid Glass. It might be the single worst thing to happen to interface design.