Glassmorphism CSS Tutorial: Build Stunning Frosted Glass UI

Glassmorphism CSS Tutorial: Build Stunning Frosted Glass UI

April 22, 2026
10 min read

What you'll learn

  • What glassmorphism is and why it became a dominant UI trend
  • The four CSS properties that power every glass effect
  • Browser compatibility table with percentage support data
  • A complete step-by-step frosted glass card with full code
  • Light vs dark mode glassmorphism differences
  • Common mistakes and exactly how to avoid them
  • When glassmorphism enhances UX - and when it hurts it

What Is Glassmorphism?

Glassmorphism is a UI design style that mimics frosted glass surfaces. Elements appear semi-transparent with a blurred view of whatever sits behind them, creating the illusion of depth without heavy shadows. The trend surged in popularity when Apple introduced it in macOS Big Sur (2020) and it has remained a staple of premium digital products ever since.

The look is defined by four characteristics: a translucent background, a blur applied to content behind the element, a subtle border that catches light, and a soft drop shadow to lift the card off the surface.

Frosted Glass Card

Core CSS Properties

Four properties do the heavy lifting. Understanding each one is essential before combining them.

1. backdrop-filter: blur()

This is the star of the show. It blurs everything rendered behind the element - not the element's own content. Values between 8pxand 20px produce the most realistic frosted-glass look.

backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px); /* Safari */

2. Semi-transparent rgba Background

The element must be translucent so the blurred background shows through. Light glass uses white at 10–25% opacity; dark glass uses black or dark hues at similar opacity.

/* Light glassmorphism */
background: rgba(255, 255, 255, 0.18);

/* Dark glassmorphism */
background: rgba(15, 15, 25, 0.35);

3. Subtle Border

A 1px semi-transparent white border simulates the light catching the edge of a glass surface.

border: 1px solid rgba(255, 255, 255, 0.3);

4. Soft Box Shadow

A diffuse shadow beneath the card grounds it in space without fighting the translucent look.

box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);

Browser Support

backdrop-filter has strong modern browser support (covering over 96% of global users as of 2026), but still needs the -webkit- prefix for Safari.

BrowserVersionSupportNotes
Chrome76+ Yes-
Firefox103+ Yes-
Safari9+ Yes-webkit- prefix
Edge79+ Yes-
Opera63+ Yes-
IE 11All No-

Always include both backdrop-filter and -webkit-backdrop-filter for maximum compatibility.

Step-by-Step: Building a Glass Card

A glass element only works when placed on top of a colorful or photographic background. The wrapper element creates that background.

HTML Structure

<div class="glass-wrapper">
  <div class="glass-card">
    <h2>Welcome back</h2>
    <p>Your dashboard is ready.</p>
    <button class="glass-btn">Get Started</button>
  </div>
</div>

Full CSS

/* 1. Colorful background wrapper - glass needs something to blur */
.glass-wrapper {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

/* 2. The glass card */
.glass-card {
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  padding: 2.5rem;
  max-width: 400px;
  width: 100%;
  color: #fff;
}

/* 3. Glass button */
.glass-btn {
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 10px;
  color: #fff;
  padding: 0.6rem 1.5rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.glass-btn:hover {
  background: rgba(255, 255, 255, 0.35);
}

Light vs Dark Glassmorphism

The same blur technique produces distinct personalities depending on whether you use white or dark glass.

Light Glass

.glass-light {
  background:
    rgba(255, 255, 255, 0.18);
  border:
    1px solid
    rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter:
    blur(12px);
}

Airy and modern. Best on colourful or photographic backgrounds.

Dark Glass

.glass-dark {
  background:
    rgba(10, 10, 20, 0.4);
  border:
    1px solid
    rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter:
    blur(16px);
  color: #e2e8f0;
}

Sophisticated and dramatic. Suits dark-mode dashboards and overlays.

Common Mistakes to Avoid

Applying glass to a plain white/black background

Glassmorphism only works when there is visual content behind the element to blur. Always wrap it in a gradient or image background.

Forgetting the -webkit- prefix

Safari requires -webkit-backdrop-filter. Always include both declarations.

Text contrast too low

Semi-transparent elements reduce text contrast. Use font-weight: 600+ and add a subtle text-shadow: 0 1px 3px rgba(0,0,0,0.3) for legibility.

Too many glass layers stacked

Each blur layer has a rendering cost. Limit nesting - one or two glass layers per viewport is usually the maximum before performance degrades on mobile.

Opacity set on the element not the background color

Set opacity on the rgba() background value, not on the element itself. Element opacity also fades child content and breaks the effect.

When to Use (and Avoid) Glassmorphism

Good use cases

  • Hero overlays on rich photography
  • Login / signup modals
  • Dashboard widgets on gradient backgrounds
  • Notification toasts and tooltips
  • Navigation drawers and sidebars
  • macOS / iOS-style app UIs

Avoid glassmorphism for

  • Dense text-heavy content pages
  • Data tables with many rows
  • Plain white or black backgrounds
  • Users who prefer reduced motion/transparency (respect prefers-reduced-transparency)
  • Mobile apps where GPU performance is limited
/* Respect user accessibility preferences */
@media (prefers-reduced-transparency: reduce) {
  .glass-card {
    background: rgba(30, 30, 50, 0.92);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

Key Takeaways

  • Four properties: backdrop-filter, rgba background, border, and box-shadow
  • Always place glass elements on colourful backgrounds - they need content to blur
  • Include -webkit-backdrop-filter for full Safari support
  • Limit to 1–2 glass layers per viewport to maintain performance
  • Add prefers-reduced-transparency fallback for accessibility

Share this article

Build Glass Effects Visually

Dial in your blur, opacity, border, and background with real-time preview - then copy the production-ready CSS with one click.