The Complete Guide to CSS Glassmorphism (Frosted Glass Effect)
To create a frosted glass effect in modern CSS, combine backdrop-filter: blur(16px) with both vendor prefixes (-webkit-backdrop-filter for Safari), a semi-transparent background (rgba(255, 255, 255, 0.1)), a 1px translucent border highlight, and an elevation shadow.
Text remains crisp while the vibrant gradient underneath is softly diffused in real time.
The 4 Pillars of Realistic Glassmorphism
Many beginner developers attempt glassmorphism by simply writing opacity: 0.5. That results in washed-out text and muddy colors. True glassmorphism depends on four optical layers:
- Background Diffusion (
backdrop-filter: blur(...)): Softens what is behind the element. - Translucent Surface (
rgba()oroklch()): Gives the glass its subtle body or tint. - Reflective Chamfer Edge (
border: 1px solid rgba(...)): Simulates the light catch on cut glass. - Elevation Shadow (
box-shadow): Separates the glass pane from the background plane.
.glass-card {
/* 1. Translucent Tint (White Glass) */
background: rgba(255, 255, 255, 0.12);
/* 2. Frosted Blur Filter (Both standard & WebKit) */
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
/* 3. High-Reflectivity Edge */
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 16px;
/* 4. Ambient Soft Shadow */
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
/* Typography */
color: #ffffff;
}
Dark Mode Glassmorphism with Modern OKLCH
On dark interfaces, white glass can look washed out. Instead, use dark-mode glass tinted with OKLCH or hex alpha:
.dark-glass {
background: oklch(0.2 0.02 260 / 0.65);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
color: #f1f5f9;
}
Next-Level Addons: Making Glass Cards Feel Physical
Basic frosted glass looks clean, but combining glassmorphism with physics, lighting, and modern color spaces transforms flat cards into interactive tactile surfaces:
A trick I use in almost every project: don't fight specificity battles with !important. Leverage modern CSS cascade layers (@layer) and CSS variables as design tokens—it makes dark/light theme switching and responsive tuning effortless.
Frequently Asked Questions
Practical answers to common questions about backdrop filters, Safari compatibility, and WCAG text contrast.
Why is backdrop-filter: blur() not working in Safari?
Safari on both iOS and macOS requires the vendor prefix -webkit-backdrop-filter. Always declare both:
-webkit-backdrop-filter: blur(16px);
backdrop-filter: blur(16px);
Additionally, check that:
- Your background has alpha transparency (an opaque hex like
#ffffffwill cover the blur). - No parent element has
overflow: hiddencombined withwill-change: transform, which can trigger an Apple WebKit rendering bug.
What is the difference between opacity and background alpha for glassmorphism?
The CSS opacity property affects the entire element and every child node inside it. If you set opacity: 0.2, all your headings, paragraphs, and buttons will become 80% transparent, ruining readability.
In contrast, setting alpha only on background-color (e.g. rgba(255, 255, 255, 0.15)) keeps all text, icons, and interactive elements 100% solid.
How do you maintain WCAG text contrast on glassmorphic backgrounds?
Because users scroll dynamic imagery or text behind your glass cards, background luminance changes unpredictably.
To guarantee WCAG AA compliance (4.5:1 contrast ratio):
- Use a darker tint (e.g., 60% opacity dark glass) on content-heavy body cards.
- Add a subtle text shadow:
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8). - Use
@supports not (backdrop-filter: blur(10px))to provide a solid opaque fallback for legacy browsers.
How do you prevent backdrop-filter from causing lag on low-end mobile phones?
Real-time GPU backdrop blurring requires substantial raster cache memory. To keep scrolling smooth on mobile devices:
- Keep the blur radius under 20px (e.g.,
blur(12px)rather thanblur(40px)). - Avoid nesting multiple blurred cards directly on top of each other.
- Ensure the element has its own GPU composition layer using
will-change: transformsparingly on animated dialogs only. - Provide an
@supports not (backdrop-filter: blur(10px))solid fallback for older engines.
Can you use CSS backdrop-filter on SVG vector elements?
HTML elements containing inline SVGs or HTML5 <foreignObject> tags can inherit backdrop-filter blur directly. However, standard SVG vector elements like <rect> or <path> cannot read underlying HTML pixels via CSS backdrop-filter.
For pure SVG graphics, use SVG filter primitives such as <filter id="blur"><feGaussianBlur stdDeviation="8"/></filter> to create blurred lighting effects.