CSS Glass Effect (Frosted Glass with backdrop-filter)
The CSS glass effect (also called frosted glass or glassmorphism) makes an element look like a sheet of blurred glass sitting on top of the background. It takes three things: a semi-transparent background, backdrop-filter: blur(), and a thin light border.
Here’s a ready-to-use version you can copy into your project.
Demo:
Frosted glass
The background behind this card is blurred with backdrop-filter.
How the glass effect works
background: rgba(255, 255, 255, 0.12): a mostly transparent white, so the colors behind show through.backdrop-filter: blur(12px): blurs everything behind the element. This is what makes it look like frosted glass. More blur looks more frosted.border: 1px solid rgba(255, 255, 255, 0.25): a light edge that catches the light like the rim of a glass pane.box-shadow: lifts the card off the background.
The effect only shows up on top of something colorful. On a plain white or black background there’s nothing to blur. Make a colorful background with the CSS gradient generator.
Dark glass variant
For dark UIs, swap the white tint for a dark one and blur a bit more:
.glass-dark {
color: #fff;
background: rgba(15, 23, 42, 0.45);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 16px;
-webkit-backdrop-filter: blur(16px) saturate(140%);
backdrop-filter: blur(16px) saturate(140%);
}
Browser support and fallback
backdrop-filter works in all modern browsers. Keep the <code>-webkit-</code> prefix for older Safari versions. For browsers without support, use a more opaque background so text stays readable:
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
.glass-demo__card {
background: rgba(15, 23, 42, 0.85);
}
}
Want to tweak the blur, transparency and color visually? Use the Glassmorphism CSS Generator and copy the generated code.