Glassmorphism in CSS: how it works + a free live generator
Glassmorphism is the frosted glass look you see on Apple's interfaces, in Windows, and on half of the landing pages on Dribbble: a translucent card that blurs whatever is behind it, with a thin bright edge that catches t
Glassmorphism is the frosted glass look you see on Apple's interfaces, in Windows, and on half of the landing pages on Dribbble: a translucent card that blurs whatever is behind it, with a thin bright edge that catches the light.
It looks expensive, but in CSS it comes down to four properties. This guide explains each one, gives you a copy-paste class, covers the mistakes that make glass look like grey plastic, and links to a free live generator where you can tune every value with sliders and copy the result.
π Open the live glassmorphism generator: drag the sliders, watch the card change, press Get the CSS.
The four ingredients of glass
Real frosted glass does four things to the light that passes through it. Each one maps to a line of CSS.
1. A faint tint
Glass is never fully clear. A white background at 10β20% opacity gives it body:
background: rgb(255 255 255 / 0.14);
Go above about 30% and it stops looking like glass and starts looking like a white card.
2. Blur what's behind it
This is the heart of the effect. backdrop-filter applies a filter to everything behind the element, not to the element itself:
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px); /* Safari */
Between 10px and 24px looks like frosted glass. Under 6px it just looks smudged.
3. Boost the saturation
Blurring washes colours out. Real glass doesn't. Add saturate() in the same filter and the colours behind the card come back to life:
backdrop-filter: blur(18px) saturate(160%);
This one line is the difference between "nice" and "wow". Most tutorials skip it.
4. A lit edge
Light catches the edge of a pane of glass. A thin, semi-transparent white border plus a 1px inner highlight on top sells the thickness:
border: 1px solid rgb(255 255 255 / 0.28);
box-shadow:
0 30px 60px -20px rgb(0 0 0 / 0.55), /* lifts it off the page */
inset 0 1px 0 rgb(255 255 255 / 0.38); /* light on the top edge */
The complete class
Put the four together and you have a reusable glass panel:
.glass {
background: rgb(255 255 255 / 0.14);
backdrop-filter: blur(18px) saturate(160%);
-webkit-backdrop-filter: blur(18px) saturate(160%);
border: 1px solid rgb(255 255 255 / 0.28);
border-radius: 22px;
box-shadow:
0 30px 60px -20px rgb(0 0 0 / 0.55),
inset 0 1px 0 rgb(255 255 255 / 0.38);
color: #fff;
}
Want different values? Don't guess and refresh. Tune them live in the generator: blur, saturation, tint, edge light, corner radius and colours are all sliders, and Get the CSS gives you this exact rule with your numbers.
Why your glass looks like grey plastic
If you copied a glass class and it looks flat, it's almost always one of these.
There's nothing behind it. Blur only shows when there is something to blur. On a flat background, glass is just a grey box. Put colourful shapes, a photo or a gradient behind it. In the generator, three blurred circles drift behind the card for exactly this reason.
The tint is too strong. Above roughly 0.3 opacity the background wins and the blur disappears. Start at 0.1 and go up slowly.
You forgot saturation. Blur alone desaturates. Add saturate(140%β180%).
No edge. Without the thin white border the card has no thickness and melts into the background.
Dark text on a busy background. Glass changes as things move behind it, so text needs contrast everywhere. White text with a soft shadow, or a slightly stronger tint behind long text, keeps it readable.
Browser support and performance
backdrop-filter works in every current browser: Chrome, Edge, Firefox (since version 103) and Safari (keep the -webkit- prefix for older iOS versions).
It isn't free, though. The browser has to re-blur everything behind the element whenever something under it moves. A few glass panels are fine. Dozens of large, overlapping ones on an animated page will cost frames, especially on low-end phones. Two tips:
- Keep blurred areas small and few. Use glass for cards, navbars and dialogs, not whole page sections.
- If you need a fallback for very old browsers, give the element a stronger solid tint first, then add the blur inside
@supports (backdrop-filter: blur(1px)) { β¦ }.
Accessibility
Glass is decoration, so make sure it doesn't cost readability:
- Check text contrast against the busiest part of what can sit behind the card, not the calmest.
- Respect
prefers-reduced-transparencywhere it's supported, and fall back to a solid background:
@media (prefers-reduced-transparency: reduce) {
.glass { background: rgb(30 30 36 / 0.95); backdrop-filter: none; }
}
Try it yourself
Reading about blur values only goes so far. The fastest way to get a feel for glassmorphism is to drag the sliders and watch:
- Open the glassmorphism generator and move the Blur, Saturation and Glass tint sliders.
- Press Get the CSS to copy your version.
- Want to keep it, change the background or build your own card on top? Remix it on Devlyo: you get your own editable copy that runs live, and you can share it with a link.
Devlyo is a place for developers to share code that actually runs: live components, shaders and Three.js demos with sliders anyone can play with. If you build a glass effect of your own, post it there, and the best ones get featured.
Originally published on Devlyo, where you can play with the live generator.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.