EthicsComputerCourses
Join training +91 90532 10052

Glassmorphism Design

CSS · Lesson 156 of 240 Advanced 11 min read Updated

By the end of this lesson you will build frosted glass cards over a colourful background, give them believable edges and highlights, measure and fix their text contrast, and ship them safely with a fallback, a reduced-transparency rule and a performance budget for low-cost phones.

Know these first: Backdrop Filter (how the property works, the -webkit- prefix and Baseline 2024 status), Box Shadow (inset and layered shadows), CSS Gradients: Advanced and @supports Feature Queries. This lesson does not repeat them. It turns them into a design style and asks when that style helps users.

What glassmorphism is

Think of the frosted glass door of a bank cabin. You can see colours and movement behind it, but no details. Anything stuck on the glass, like a printed "Manager" sign, stays sharp. Glassmorphism is a UI style built on that idea: panels look like frosted glass floating over a bright background. The name became popular around 2020.

The style has five ingredients. Leave one out and it stops looking like glass.

IngredientCSSWhy it is needed
Something colourful behindgradients or an image on the pageBlurring a plain white page shows nothing
A see-through tintbackground: rgb(255 255 255 / 0.15)Lets the blur show and calms it down
Blurbackdrop-filter: blur(16px)Removes detail so the panel reads as a surface
A light edgea semi-transparent borderGlass catches light at its edges
Deptha soft outer box-shadowLifts the panel off the background

Here is the version you see on design showcase sites: a balance card for an imaginary UPI wallet called Kesar Pay, over three bright circles. Run it and look closely at the text.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Glass wallet card</title>
  <style>
    body {
      margin: 0;
      min-height: 100vh;
      display: grid;
      place-items: center;
      font-family: system-ui, sans-serif;
      background:
        radial-gradient(circle at 38% 38%, #facc15 0 90px, transparent 91px),
        radial-gradient(circle at 64% 42%, #f472b6 0 80px, transparent 81px),
        radial-gradient(circle at 52% 70%, #6d28d9 0 100px, transparent 101px),
        linear-gradient(135deg, #1e1b4b, #0f766e);
    }
    .card {
      width: min(300px, 85vw);
      padding: 24px;
      border-radius: 20px;
      color: white;
      background: rgb(255 255 255 / 0.15);
      -webkit-backdrop-filter: blur(16px) saturate(1.4);
      backdrop-filter: blur(16px) saturate(1.4);
      /* light hits the top-left edges harder */
      border: 1px solid rgb(255 255 255 / 0.2);
      border-top-color: rgb(255 255 255 / 0.6);
      border-left-color: rgb(255 255 255 / 0.6);
      box-shadow:
        inset 0 1px 0 rgb(255 255 255 / 0.4),
        0 12px 32px rgb(15 23 42 / 0.35);
    }
    .card p { margin: 0; font-size: 0.9rem; }
    .card .amount { margin: 6px 0 18px; font-size: 2rem; font-weight: 700; }
  </style>
</head>
<body>
  <section class="card">
    <p>Kesar Pay balance</p>
    <p class="amount">₹12,450</p>
    <p>Last top-up: ₹2,000 on 14 Nov</p>
  </section>
</body>
</html>

What you should see: a soft, glowing card. The circles look sharp outside it and turn into colour washes inside it. The top and left edges are brighter than the others, as if light falls from the top left. The thin inset shadow adds a bright line just inside the top edge, like the polished rim of real glass.

Now look at the small white text where it sits over the yellow circle. It is hard to read. That is the central problem of this style.

Edges and highlights

Real glass is visible mainly because of its edges. Three small techniques sell the effect:

  • Uneven border colours. Brighter top and left borders suggest a light source. Keep the other sides at about 20 percent white so the edge never disappears.
  • An inset highlight. inset 0 1px 0 rgb(255 255 255 / 0.4) draws a one-pixel line inside the top edge.
  • A sheen. A faint diagonal gradient over the tint, such as linear-gradient(135deg, rgb(255 255 255 / 0.25), rgb(255 255 255 / 0.05)), brightens one corner.

Keep these subtle, or people look at the frame instead of the content.

Why glass fails contrast, and how to measure it

Text contrast is the ratio between the brightness of the text and the brightness behind it. WCAG asks for at least 4.5:1 for normal text and 3:1 for large text (see Color Contrast & WCAG). On a normal card, "behind it" is one colour. On glass, it is a mix that changes with every pixel and every scroll position.

You can estimate it. The browser paints your tint over the blurred backdrop, so the colour behind the text is roughly:

Text
result = tint colour x tint alpha + backdrop colour x (1 - tint alpha)

Work it out for the worst backdrop, not the average. For white text these are the brightest colours that can sit behind the card. Here are the numbers for the Step 1 card and two fixes:

GlassBackdropMixed colourContrast with the text
15% white tint, white textyellow #facc15rgb(251 212 56)1.44:1, fails
15% white tint, white textviolet #6d28d9rgb(131 72 223)5.31:1, passes
60% dark tint #0f172a, white textyellow #facc15rgb(109 95 34)6.34:1, passes
70% white tint, dark text #0f172aviolet #6d28d9rgb(211 191 244)10.65:1, passes

The same card passes over violet and fails badly over yellow, so checking one spot gives a false pass. Blur and saturate() shift the real pixels a little: confirm with a colour picker on a screenshot.

The fixes, from strongest to weakest:

  1. Raise the tint opacity. 55 to 75 percent is typical for body text.
  2. Match the text colour to the tint. White text on a dark tint, dark text on a light tint.
  3. Calm the background behind text areas. Keep bright shapes away from where text sits.
  4. Use larger, bolder text. Large text only needs 3:1. Thin fonts on glass are the worst case.

A soft text-shadow helps a little, but contrast checks do not count it.

Step 2: an accessible glass card

Now the same background with two cards. The left card is the Step 1 recipe. The right card is a production-ready version for a school portal: a stronger dark tint, a safe fallback, and rules for people who ask for less transparency or more contrast.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Weak and accessible glass</title>
  <style>
    body {
      margin: 0;
      min-height: 100vh;
      display: flex;
      flex-wrap: wrap;
      gap: 20px;
      align-items: center;
      justify-content: center;
      padding: 24px;
      box-sizing: border-box;
      font-family: system-ui, sans-serif;
      background:
        radial-gradient(circle at 30% 45%, #facc15 0 110px, transparent 111px),
        radial-gradient(circle at 72% 50%, #fb923c 0 110px, transparent 111px),
        linear-gradient(135deg, #1e1b4b, #0f766e);
    }
    .card {
      width: 230px;
      padding: 20px;
      border-radius: 18px;
      color: white;
      border: 1px solid rgb(255 255 255 / 0.3);
      box-shadow: 0 12px 32px rgb(15 23 42 / 0.35);
    }
    .card h2 { margin: 0 0 6px; font-size: 1.1rem; }
    .card p { margin: 0; line-height: 1.5; }

    .weak {
      background: rgb(255 255 255 / 0.15);
      -webkit-backdrop-filter: blur(16px);
      backdrop-filter: blur(16px);
    }

    /* 1. Safe default: almost solid, readable without blur */
    .glass { --tint: rgb(15 23 42 / 0.9); background: var(--tint); }

    /* 2. Browsers that can blur get the lighter glass */
    @supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
      .glass {
        --tint: rgb(15 23 42 / 0.6);
        -webkit-backdrop-filter: blur(16px) saturate(1.2);
        backdrop-filter: blur(16px) saturate(1.2);
      }
    }

    /* 3. Users who asked for less transparency or more contrast */
    @media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
      .glass {
        --tint: rgb(15 23 42);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
      }
    }
  </style>
</head>
<body>
  <section class="card weak">
    <h2>Class 9 results</h2>
    <p>Results for the half-yearly exams are out. Check your marks before Friday.</p>
  </section>
  <section class="card glass">
    <h2>Class 9 results</h2>
    <p>Results for the half-yearly exams are out. Check your marks before Friday.</p>
  </section>
</body>
</html>

What you should see: the left card's text almost vanishes over the yellow circle. The right card sits over an equally bright orange circle and still looks like glass, but its text is clear everywhere. The order of the three rules matters. The safe default comes first, the glass upgrade second, and the user preference last, so the preference always wins.

In Windows contrast themes (forced colours mode), browsers replace your colours with the user's palette and remove box-shadow, so the glass becomes a plain panel. The border survives with a system colour, which is why glass should keep a real border.

Performance on budget phones

A blur is costly. Whenever something behind the glass changes (a scroll, a video, an animation), the browser must blur those pixels again for that frame. A laptop hides this. A ₹8,000 Android phone with a weak graphics chip drops frames.

Set yourself a budget:

  • One or two glass surfaces per screen. A header and a dialog, or a hero card. Not every card in a product grid.
  • No glass in long scrolling lists. Forty frosted cards in a feed means forty blurs on every scroll frame.
  • Moderate blur. 8px to 16px removes detail. Very large radii cost more and look no better.
  • Never animate the blur value. Fade or move the panel with opacity and translate instead.
  • Test slowly. In Chrome DevTools, open the Performance panel and set CPU throttling to a 4x or 6x slowdown, then scroll. Better still, test on a real low-cost phone.

If scrolling still stutters, drop the blur on small screens and use a stronger tint. Screen width is only a rough guess at device power, but it is the best signal CSS has:

CSS
@media (max-width: 480px) {
  .glass {
    --tint: rgb(15 23 42 / 0.88);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

When to use glass

Glass suits short content over something visual: a hero card over a photo, a music player over album art, a modal, a navigation bar. It suits long reading, dense tables and long forms badly, because the shifting background fights the user on every line.

Common mistakes

  • Checking contrast at one spot. The text must pass over the brightest and the darkest colour that can sit behind it.
  • White text on a thin white tint. It looks great in a mockup with a dark background and fails as soon as something bright moves behind it.
  • Glass inside glass. In Chrome and Edge, an element with backdrop-filter limits what nested glass can see, so the inner panel has almost nothing to blur. Give inner panels a plain translucent fill.
  • No fallback. Without @supports, a browser that cannot blur shows a thin tint over sharp, busy shapes.
  • Glass everywhere. Too many blurred layers hurt both performance and hierarchy. Glass works because it is special.

Interview questions

1. What are the essential CSS ingredients of glassmorphism?

A colourful or image background behind the element, a semi-transparent background colour on the element, and backdrop-filter: blur() to soften what is behind. A light semi-transparent border and a soft shadow complete the look. Without something interesting behind, the effect is invisible.

2. Why is text contrast hard to guarantee on glass?

The colour behind the text is a mix of the tint and whatever is behind the panel, and that changes as the page scrolls or the background moves. You must check contrast against the worst possible backdrop. The reliable fix is a stronger tint, usually 55 to 75 percent for body text, with a text colour that suits the tint.

3. How would you write a safe fallback for glassmorphism?

Make the default style nearly opaque so it is readable without blur. Inside @supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)), lower the opacity and add the blur. Put user-preference rules such as prefers-contrast: more after both so they win.

4. What happens to a glass card in forced colours mode?

The browser replaces backgrounds and text colours with the user's system colours and removes box shadows, so the card becomes a plain panel. Borders stay and get a system colour. That is why a real border is better than a shadow-only edge.

5. Why can glassmorphism hurt performance, and how do you limit it?

The backdrop has to be blurred again on every frame where something behind it changes, such as during scrolling. Limit glass to one or two small surfaces per screen, keep the blur moderate, never animate the blur value, and test with CPU throttling or a real budget phone.

Key points

  • Glassmorphism needs five ingredients: a colourful backdrop, a translucent tint, blur, a light edge and a soft shadow.
  • Uneven border colours and a one-pixel inset highlight make the edge look like real glass.
  • Estimate contrast with the tint-over-backdrop mix, and check it against the worst backdrop, not the average.
  • Fix weak glass with a stronger tint and a matching text colour; text shadows are not a substitute.
  • Write a readable default, upgrade inside @supports, and let prefers-reduced-transparency and prefers-contrast switch back to solid.
  • Keep glass to one or two surfaces per screen, never animate the blur, and test on a slow phone.

Exercise

Ananya is designing a weather widget for a Jaipur tourism site. Over a background of two bright radial-gradient circles (one orange, one sky blue) on a dark gradient, build a glass card that shows the city, the temperature in large text and a one-line forecast. Use a light tint with dark text this time. Add uneven border colours and an inset highlight, a nearly solid fallback outside @supports, and a rule that removes the blur for prefers-reduced-transparency and prefers-contrast: more. Estimate the contrast of your text over the darker part of the background.

Show solution
HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Jaipur weather</title>
  <style>
    body {
      margin: 0; min-height: 100vh; display: grid; place-items: center;
      font-family: system-ui, sans-serif;
      background:
        radial-gradient(circle at 40% 40%, #fb923c 0 90px, transparent 91px),
        radial-gradient(circle at 60% 62%, #38bdf8 0 100px, transparent 101px),
        linear-gradient(160deg, #172554, #3b0764);
    }
    .weather {
      --tint: rgb(255 255 255 / 0.94);
      width: 240px; padding: 20px; border-radius: 18px;
      color: #0f172a; background: var(--tint);
      border: 1px solid rgb(255 255 255 / 0.3);
      border-top-color: rgb(255 255 255 / 0.8);
      border-left-color: rgb(255 255 255 / 0.8);
      box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.6), 0 12px 32px rgb(15 23 42 / 0.4);
    }
    @supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
      .weather {
        --tint: rgb(255 255 255 / 0.7);
        -webkit-backdrop-filter: blur(14px);
        backdrop-filter: blur(14px);
      }
    }
    @media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
      .weather { --tint: white; -webkit-backdrop-filter: none; backdrop-filter: none; }
    }
    .weather h1 { margin: 0; font-size: 1rem; }
    .temp { margin: 4px 0; font-size: 2.5rem; font-weight: 700; }
    .weather p { margin: 0; }
  </style>
</head>
<body>
  <section class="weather">
    <h1>Jaipur</h1>
    <p class="temp">29°C</p>
    <p>Clear skies, light breeze in the evening.</p>
  </section>
</body>
</html>

The worst case for dark text is the darkest backdrop, the deep blue #172554. A 70 percent white tint over it mixes to about rgb(185 190 204), which gives #0f172a text a contrast of about 9.6:1, well above 4.5:1. The fallback and preference rules keep the card readable in every browser.

Quick Quiz

1. A glass card uses a 15 percent white tint and white text. Where is its contrast worst?

2. Which change most reliably fixes poor text contrast on glass?

3. Why should user-preference media queries come after the @supports glass rule?

4. Which is the best performance advice for glassmorphism?

Learn CSS with a mentor

Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call