8 ms·
Show HN: CSS generator for a high-def glass effect
There are lots of glassmorphism generators out there, but I wanted to push the effect further! This project is the result of months of experimenting with CSS property layering and battling browser quirks.
Cross-browser compatibility is actually the reason I rely on ::before and ::after pseudo-elements to build up the effect. Move the color/opacity to the main element, and you’ll get weird color bleed on the corners in Chrome. Move the texture, and it muddles the bevel’s specular highlight. Move the bevel, and it gets blurred out by the backdrop-filter. And so on!
Layers include:
* Adjustable blur, brightness, and saturation (backdrop-filter)
* Subtle translucent texture
* Faux 3D bevel (using box-shadows, not an outline)
Glassmorphism is rather heavy on resources, so it’s best used as an accent and avoided on wide desktop elements.
Should be compatible with recent versions of Chrome, Safari, and Firefox (desktop and mobile). If you spot bugs or rendering glitches, I’d love to know!
Side note: this is an early preview of a framework-agnostic glass SCSS/component library I’m building.
- thecosas 1y agoI can see people using this to have their websites (or apps) fit into the design of Apple's OS 26 design language. Neat!
- CharlesW 1y agoFWIW, this looks nothing like the iOS 26 (which I’ve been using on my primary phone) Liquid Glass effects.
- kris-kay 1y agoTrue, but it wasn't meant to. I installed the 2nd beta on my phone as well and like it so far.
- kris-kay 1y agoThanks, I hope it can be useful for people, especially when I make the library public.
- lovegrenoble 1y agoso good!
- mbforbes 1y agoReally nicely done! It's always surprising to me how often computer graphics isn't "one weird trick" and more like "5 layered tricks." Doing it with cross-browser compat is an additional challenge. Do you have a sense of which aspects are the most resource-intensive? Naively I would guess it's the backdrop-filter.
- kris-kay 1y agoYes, same! I didn't expect it to need so many tricks to implement. Your intuition is correct, the most resource-intensive part is the blur bit of the backdrop-filter. The higher the blur value, the more neighbouring pixels need to be "consulted" before rendering. Another resource-intensive aspect is continuous repaint as you scroll or as a video background changes the look of the glass.
- whycome 1y agoAnd sometimes it's 5 layered tricks just to "center" something.
- kris-kay 1y agoNot anymore! We live in the golden age of display: grid; + place-items: center;
- chrismorgan 1y agoThis suffers from the problem of only blurring using the pixels immediately behind the surface, as demonstrated well in https://www.joshwcomeau.com/css/backdrop-filter/#the-issue https://www.joshwcomeau.com/css/backdrop-filter/#the-issue. That and the discussion in https://news.ycombinator.com/item?id=42302907 https://news.ycombinator.com/item?id=42302907 are good reading. If the backdrop is going to move underneath, this is fairly important; if it will be static, it’s not normally important.
- kris-kay 1y agoI did read Josh's great article and had a go at implementing the tutorials. Unfortunately, I ran into some issues with the border-radius via SVG mask bit. It worked great on a hardcoded element, but I still need to figure out how to make it work across a whole component library where the border-radius changes based on the user's branding and container-queries.
- andrewmcwatters 1y agoJosh’s solution also intuitively appears wrong to me because it seems to assume that nearby elements are emissive, and I can’t agree with that as a standard physical property of “materials” on the web. I instead assume that materials are by default more similar to paper.
- chrismorgan 1y agoThe backdrop blur is unrelated to the surface properties of the elements underneath: it’s about the frosted glass refracting light, and some of that light it refracts comes from beyond its bounding box, which a naive backdrop-blur won’t observe.
- andrewmcwatters 1y agoFrosted glass doesn’t pass through light of objects that are simply near by it. It doesn’t make physical sense. I understand the defect, but neither does this solution correctly fix the problem. Note the circle before it intersects with the rect, without accounting for pixels beyond the bounds, the blur is incorrect because the kernel doesn’t take into effect the circle. Note the blur after extending the kernel beyond the visible bounds. While the blur is correct, the albedo of the shape passing through the rect no longer makes sense. The circle is not emissive, and yet despite this, you see the blur of the circle behind the rectangle without it intersecting in a full-bright environment. Why can we assume the environment is full-bright? Because there is no lighting. Only albedo. Neither are correct.
- jauntywundrkind 1y agoLooks pretty good. But missing out on the refractive aspect of glass takes away the strong visual separation of layers that IMO is Liquid Glass's biggest contribution. Material has these wonderful designer resources showing how the app ought to be built of consistent moving layers, shown in 3D from the side. It's clear that there's these layers. But once you go 2d, put it all together, its incredibly hard for me to find all the features. The number of times that there's an action button in some corner that folks don't see massive. Motion sort of helps highlight the chrome vs content, but there's just so little thats visually defining. Liquid Glass's biggest strength IMO is the edge distortion. That when the content moves, there's this non-linear motion that the human visual sense immediately picks up on. Static screenshots don't always look great, but in motion there's so much more distinction of elements than anything else I've seen. And that key refractive element, that takes such huge advantage of human's motion sensing, is missing here. I'd seen one other great web web demo, but am struggling to find it right now. I did find this one, which I don't think looks as good, and the performance is bad for me here on mobile. But it nicely breaks down steps and shows how complex a task this can be. Getting these edge distortions in is hard, and relying on SVG filters to do it is a brutal path to hack together. https://atlaspuplabs.com/blog/liquid-glass-but-in-css#breaking-down-the-effect https://atlaspuplabs.com/blog/liquid-glass-but-in-css#breaki... There is a collection of attempts (CodePen Spark) at Liquid Glass that I just found. Second link is one I thought did a pretty nice job, via very specifically pre defined / hard coded SVG. https://codepen.io/spark/453 https://codepen.io/spark/453 https://codepen.io/lucasromerodb/pen/vEOWpYM https://codepen.io/lucasromerodb/pen/vEOWpYM
- jasonthorsness 1y agoI think this is a clever moat Apple created with Liquid Glass: they picked an effect that is easy to make a worse version of, but very hard to do the real/right way (and humans have an intuition for real/right because they see real glass every day). So any copycats will look worse in a way that's pretty obvious and Apple gets to keep the "premium-looking" product.
- gumby271 1y agoI think the same is true for when they started using blurs everywhere. They knew Android OEMs would copy it in a worse way and shoot themselves in the foot. That's also why material design doesn't rely on blur effects, it needs to run well on much worse hardware. It's fun seeing the attempts to mimic Liquid Glass though, the most impressive so far is this Flutter package: https://pub.dev/packages/liquid_glass_renderer https://pub.dev/packages/liquid_glass_renderer
- tempodox 1y agoWow, that Video tab looks gorgeous. I still don't understand yet how it's actually done.
- kris-kay 1y agoThanks! Do you mean how the glass or how the video background is done?
- tempodox 1y agoThe background.
- kris-kay 1y agoSo you need a video HTML tag with all of these attributes: <video autoplay muted loop webkit-playsinline playsinline sizes="100vw"> and the CSS: .bg-video { position: fixed; z-index: -1; inset: 0; width: 100%; (don't set this to 100vw or you will have scrollbar issues) height: 100%; min-height: 100vh; object-fit: cover; object-position: center; pointer-events: none; } The part I still need to do myself is provide multiple video sizes and show the one that's most suitable for the viewport.
- account42 1y ago> playsinline Oh great, yet another tag you need to add to tell mobile browsers to do the right thing instead of fucking with your website for no reason.
- elpocko 1y agoIs this considered new design? What is special about it? I don't see much of a difference compared to the Aero glass effect in Windows Vista from 2006. I've also seen it on many websites, using `backdrop-filter: blur`. Or am I missing something?
- rpastuszak 1y agoYou’re not looking far back enough:) I see it more as a new Aqua from OSX Cheetah (2000 CE) This is a slight tangent, but 20 years ago I had a nightmare in which I got hit by a tram, died and travelled in time into a world where every computer was running Windows Vista. In other words, fair enough, you might be onto something here after all.
- elpocko 1y ago>Aqua from OSX Cheetah I've never used OSX, but I would guess from screenshots that it didn't do dynamic layered gaussian blur of large screen regions in realtime, which would've been too much for the hardware of the year 2000.
- rpastuszak 1y agoThat is true, but don't forget water is the essence of moisture. Also, those scrollbars were quite impressive for their time.
- account42 1y agoI always thought they were extremely kitschy, just like the Windows XP window frames.
- kris-kay 1y agoThe 2000 CE bit made me laugh! And yes, Windows Vista was a proper nightmare.
- kris-kay 1y agoYou're right, glassmorphism dates back to the early years of this millennium. For instance, Project Looking Glass(2003) attempted an entire desktop environment that resembled slabs of glass that could be turned over in 3D space! Even so, I haven't found another glass generator that has a texture layer and box-shadow bevel, etc.
- magic_hamster 1y agoIt's a nice effect, but to me this doesn't really feel like glass. I think the most immediate difference is how light has no interaction with the bevels. I also expect some light to shine back into the glass and affect the lighting and coloring. It's not enough to just throw a blur in there. Also, glass can have its own shadow with some interesting caustics (not sure even Apple does this). I see the shadow here, and it feels like a simple drop shadow. It makes the box feel like a flat card more than a 3d physical object which I think is part of the new trend. Either way, This will not be easy to emulate with just css, it's probably more suitable to be a shader running in a gpu.
- ivape 1y agoIf it can't be done with CSS, then how can it be done? How can you apply GPU shader effects to a common div? If we can't apply GPU effects to basic HTML and need to do so on custom things like an arbitrary Canvas concoction, then we may as well rebuild a brand-new rendering engine that can apply GPU effects. HTML is dead. I see no reason to care about it because we only need <p> tags to get some text across, as just about everything else is used to make a webpage an ad-bomb. So let's just start again with the <p> tag and better gpu integration, and leave everything else out.
- deleted 1y ago[deleted]
- madeofpalk 1y ago> we may as well rebuild a brand-new rendering engine that can apply GPU effects. They've been trying, with various degrees of success, over the past 10 years with Houdini. https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_properties_and_values_API/Houdini https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_propert...
- deleted 1y ago[deleted]
- swyx 1y agoi collect these! https://github.com/swyxio/spark-joy https://github.com/swyxio/spark-joy others - https://ui.glass/generator/ https://ui.glass/generator/ Get started with this free CSS generator based on the glassmorphism design specifications to quickly design and customize the style properties. - frosted glass sticky header https://www.joshwcomeau.com/css/backdrop-filter/ https://www.joshwcomeau.com/css/backdrop-filter/ - glassy glassmorphism [codepen](https://codepen.io/a-trost/pen/dypQzwq https://codepen.io/a-trost/pen/dypQzwq), [in context](https://codepen.io/TurkAysenur/pen/ZEpxeYm https://codepen.io/TurkAysenur/pen/ZEpxeYm) ```css .blur-and-rotate { border-radius: 20px; backdrop-filter: blur(20px) hue-rotate(120deg); -webkit-backdrop-filter: hue-rotate(120deg); } ```
- kris-kay 1y agoNice! Spark Joy looks like an awesome resource.
- leptons 1y agoSearched for an ASCII Font generator, but didn't see one. Here's one tool I use: https://patorjk.com/software/taag/#p=testall&f=Graffiti&t=Hello%20World https://patorjk.com/software/taag/#p=testall&f=Graffiti&t=He...
- swyx 1y agoadded!
- kris-kay 1y agoJust saw that you added this project to the spark-joy list. Thanks so much!
- minaguib 1y agoLooks good Not a lot of web sites have made my Macbook M3 show signs of stress ;)
- kris-kay 1y agohaha thanks!
- jand 1y agoAre users allowed to copy the referenced egg-shell.png and host it themselves or is this connected to some sort of metric you like to gather?
- victorbjorklund 1y agoIf you got to the site hosting the image it says: /* This is mostly intended for prototyping; please download the pattern and re-host for production environments. Thank you! */
- kris-kay 1y agoYes, thank you for answering. The textures are free to use, but the URL should only be used for prototyping. Here is the website: https://www.transparenttextures.com/ https://www.transparenttextures.com/
- refulgentis 1y agoPro tip: Apple adds fancy GPU effects because Android can't rely on good GPUs, so Apple can continually define premium. Thus, the odds you're doing glass-morphism via a Gaussian blur and drop shadow in CSS, are exactly 0. They are assuredly at abstraction levels far below that. (disclaimer: worked on Pixel, did the color extraction + color system stuff for Material You)
- its-summertime 1y agoIt's meant to mimic frosted glass, not Apple's liquid glass design.
- kris-kay 1y agoYes thank you
- kris-kay 1y agoI mean you are right...but I still want to make the nicest thing I can make for the web.
- deleted 1y ago[deleted]
- armchairhacker 1y agoSmall issue: the shadow between the top and the scrollable area with the toggles and code fades out when you scroll down (presumably it should be initially hidden and fade in).
- kris-kay 1y agoGood catch! It's not a fading-in issue; the shadow is just scrolling out of view. I designed those "overhang" box-shadows to be applied to the inside of an element rather than cast down from one. I see now that I need to apply the latter kind in this case. Thanks for letting me know!
- alberth 1y agoI'd be concerned about the maintenance overhead of this ~44-lines of code vs. just 1-line of code that has a similar (while slightly less realistic) net effect: filter: blur(16px);
- andrewingram 1y agoI’m curious why. I’d have concerns about the performance of this effect, but 44 lines of CSS to achieve a higher level of polish and, dare I say, craft, doesn’t seem like something to be dismissive of at review stage.
- ivape 1y agoI have AI that can do just about everything for me, but I still need to make this tradeoff with CSS in 2025?
- ramoz 1y agoLooks great without the backdrop-filter
- mikedelfino 1y agoThat content scrolls quite slow on my phone. Is there another scrolling effect that makes it slower on purpose or it's a side effect of the glass look?
- xgpyc2qp 1y agoOn my M4 128 Gb ram works fine
- deleted 1y ago[deleted]
- jdiff 1y agoI would imagine a great many things work fine on any M4 that don't work fine on a great many phones and other devices.
- kris-kay 1y agoInteresting, no there are no scroll effects anywhere on the page. Would you mind sharing what device, browser, and level of internet connection you're using?
- mikedelfino 1y agoNever mind, I tried recording it now but could not reproduce it anymore. It was probably something on my phone at the time (Firefox on Android). I tried to remove or edit my previous comment but it seems it's not an option. Sorry for the noise.
- xgpyc2qp 1y agoLove it. Should be popular within new ios
- kris-kay 1y agoThanks!
- utopcell 1y ago> This project is the result of months of experimenting [..] It shows, this is awesome, especially that rice paper effect!
- kris-kay 1y agoThank you!
- somgautam2077 1y ago[dead]
- arfaaan 1y agoAmazing work!
- kris-kay 1y agothank you!
- suralind 1y agoIt looks so much better with some texture!
- kris-kay 1y agoI agree, even a very subtle texture makes a big difference!
- tyleo 1y agoThis looks like it uses similar techniques to my own glass implementation: https://news.ycombinator.com/item?id=42225481 https://news.ycombinator.com/item?id=42225481 Especially with respect to the abuse of box shadow.
- kris-kay 1y agoYour project looks awesome! I'm glad not to be the only one going 5+ layers deep into the shadows. The addition of Light Rays is particularly impressive!
- adamschwartz 1y agoI’m confused, but maybe two wrongs here do make a right. Please allow me to explain. Putting aside for the moment that I personally find Apple’s iOS 26 design objectionable[1], I don’t understand why `backdrop-filter: blur` is the focus of recent implementations jumping on the Liquid Glass hype train. Using background blur to create UI layer separation (often in combination with darkening/saturation or other contrast enhancements) has been around for over a decade on iOS and almost as long on the web. So what’s new here? Adding to my confusion, I’m a bit surprised folks here think this is so challenging in CSS. A few commenters have pointed to great implementations elsewhere, but I think they’re underselling them. Plainly: the solution that involves `backdrop-filter: filter(#filter)` where `#filter` references an inline SVG embedded with `<feImage/>` and `<feDisplacementMap/>` works very convincingly well. Check out this demo for example: https://codepen.io/Mikhail-Bespalov/pen/MYwrMNy https://codepen.io/Mikhail-Bespalov/pen/MYwrMNy This implementation choose to hard-code `<feImage href="data:image/png;base64,..."/>`. But if glass3d.dev chose to implement 3d highlights in a similar fashion (and wanted to support e.g. a dynamic `border-radius`) this image could easily be rendered in the browser runtime in canvas, and dumped into the CSS using `toDataURL()`. Similarly, a component library with a CSS pre-processor could generate these for any static shape at build-time. The closest thing I’ve seen to this is: https://ruri.design/glass https://ruri.design/glass These implementations are out there. Coming back to the why/should for a second though. [1] In its current realization, Liquid Glass cannot effectively replace what blur accomplishes. Because Liquid Glass layers are more transparent, the contrast issues are real, and the spectral highlights distract the eye as much as (or more than) they help make up for that lack of contrast. It draws attention to the eye where blur would relax it. It’s a UI meant for an XR system (where it arguably solves a real problem, much like a HUD does in a video game) hacked into devices where it makes no sense, all in the name of a “unified OS” design language. If any aspect of Liquid Glass is successful it will be when it’s used sparingly to delight in places that are low stakes and where other affordances are present (like a small circular button floating in the corner of the screen with hardware concentricity). A circle shape’s refractions would be smaller, softer, more symmetrical, and therefore arguably less noisy/distracting—in a way resembling a softer blurry background. Which brings me full circle back to two wrongs. This website doesn’t do anything new, but that’s why it’s good. Because the truth is, Apple failed to deliver a Siri-based LLM on a schedule it announced and is now trying to distract us with some shiny new thing. Damn, it worked.
- voidUpdate 1y agoNice! Now we can bring the awfulness of apple liquid glass to the web
- smeej 1y agoI might be missing something, but I think this would be a lot more useful to me on mobile if I could hide or collapse the box. Instead, it takes up the entire screen and I can't really even see the effect behind it. I'm still interested enough that I'll probably try it again later on a larger screen, but I think some kind of option to hide the box would go a long way!
- deleted 1y ago[deleted]
- kris-kay 1y ago> this would be a lot more useful to me on mobile if I could hide or collapse the box. Are you referring to the code preview area? In my first implementation, I had a small demo rectangle above the generator UI, but even a small one took up too much space and made the UI harder to use. If I let the whole page scroll, people got frustrated because it wasn’t obvious they needed to stay at the top of the scroll to see the rectangle they were editing. Since this tool is mainly intended for coding, I’m prioritizing the desktop experience, with mobile acting more as a quick preview and proof that it works on mobile. That said, if you know of any similar UI that works really well on mobile, please share links!
- sahil_sharma0 1y ago[dead]
- gvison 1y agoUsed to make web background, the effect is good.
- explosion-s 1y agoI've made a JavaScript version that actually refracts elements on the page, check it out: https://real-glass.vercel.app/ https://real-glass.vercel.app/
- August7337 1y agoVery nice
- anon115 1y agothis is sexy gonna use it on my projects
- v5v3 1y agoI would suggest adding a Tailwind config too, seeing as it's so prevalent.
- vrighter 1y agoI haven't heard anything but negative comments about liquid glass from any apple users I personally know. Here goes everyone else rushing to do things just because apple did them. Not everything apple does is good. This is one of those cases.
- kris-kay 1y agoThis project isn’t meant to recreate Liquid Glass. I started working on it because I needed UI that would look good over unknown or changing backgrounds, like in a video game, over video, or in my case AR.