Tutorials

Glassmorphism in CSS: frosted glass, liquid glass and how to animate it

Build glassmorphism in CSS with backdrop-filter, a light edge, grain and a moving highlight. Covers the liquid glass look, contrast, fallbacks and performance.

20 November 2026 · 12 min read

Glassmorphism is the look of a frosted pane laid over colour: the background shows through, softened, and the panel reads as a separate layer floating above it. It has been around since translucent menus in operating systems, and it came back in a big way with the newer "liquid glass" style, which adds a bright specular edge and a sense of thickness.

In CSS it comes down to one property, backdrop-filter, plus a few layers of detail that decide whether the result looks like glass or like a grey box. This guide builds a glass card step by step, adds grain and a liquid edge, animates it, and covers the parts people skip: contrast, fallbacks and the performance cost.

Pro plan

$12/month

Frosted fill, a 1px light edge and a highlight that sweeps across on hover or focus.

Hover or focus the card

The four layers of a glass panel

Every convincing glass panel has the same four parts. Drop any one of them and the effect falls apart.

  1. Something behind it. Glass over a flat black page is just a dark rectangle. The effect needs colour, shapes or an image behind the panel. In the demo that is three drifting gradient blobs.
  2. The blur. backdrop-filter: blur() blurs whatever is painted behind the element, inside its border box. saturate() after it brings back the colour that blurring washes out.
  3. A translucent fill. A white tint between 5 and 20 percent opacity gives the pane a body. A light diagonal gradient reads more like glass than a flat tint does.
  4. An edge. A 1px border in semi-transparent white, plus an inset highlight along the top, tells the eye where the pane ends and that light is hitting it.

The base CSS

.glass {
  --blur: 18px;
  position: relative;
  border-radius: 22px;
  color: #fff;
  /* light tint on top of a faint dark tint, for text contrast */
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .16), rgba(255, 255, 255, .05)),
    rgba(17, 19, 24, .28);
  border: 1px solid rgba(255, 255, 255, .18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .4),    /* top highlight */
    inset 0 -1px 0 rgba(255, 255, 255, .06),  /* faint bottom edge */
    0 18px 40px rgba(0, 0, 0, .35);           /* lift off the page */
  -webkit-backdrop-filter: blur(var(--blur)) saturate(160%);
  backdrop-filter: blur(var(--blur)) saturate(160%);
}

Keep the prefixed -webkit-backdrop-filter line. Safari needed the prefix for a long time, and older versions still in use only understand that form. Put it before the standard property.

A blur between 12 and 24px is the usual range for cards. Below about 8px the background shapes stay recognisable and compete with the text; above 30px the pane starts to look like a flat tinted panel because all the detail has gone.

Adding grain

Real frosted glass is not perfectly smooth, and a smooth gradient blur can show banding on some screens. A layer of fine noise fixes both. You do not need an image file: an SVG feTurbulence filter in a data URI generates it.

.glass-grain {
  position: absolute; inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: .35;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

Put the grain in its own element inside the card, and give the card's text position: relative so it stacks above it. Keep the opacity low; grain should be felt more than seen.

The liquid glass look

The newer "liquid glass" style, popularised by Apple's recent interface design, makes the pane feel thick. Light catches the rim, the edge is brighter on the side facing the light, and the background seems to bend slightly near the border. You can get most of that look in plain CSS without trying to copy any particular implementation.

The trick is a gradient border that is bright at two opposite corners and fades out along the sides. It uses the same mask technique as an animated gradient border: paint a gradient on a pseudo-element, then cut out everything except a 1px ring.

.glass::after {
  content: '';
  position: absolute; inset: 0;
  padding: 1px;                   /* ring thickness */
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(150deg,
    rgba(255, 255, 255, .75),
    rgba(255, 255, 255, 0) 35%,
    rgba(255, 255, 255, 0) 65%,
    rgba(255, 255, 255, .35));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}

Combined with the inset top highlight, this reads as a curved rim catching light. To push it further, add a soft white radial gradient near one corner of the fill for a specular spot, and make the corner radius generous, since sharp corners look like flat panes rather than thick ones.

True refraction, where the background visibly warps at the edge, needs an SVG displacement filter referenced from backdrop-filter: url(#filter). Browser support for SVG filter references inside backdrop-filter is inconsistent, so treat it as an extra for browsers that handle it, never as something the design depends on.

Animating glass

The blur itself is the wrong thing to animate. Changing the radius forces the browser to recompute the blurred backdrop on every frame. Animate the cheap things instead: the panel's transform, its shadow, and a highlight layer.

Hover lift

.glass { transition: transform .35s cubic-bezier(.2, .8, .2, 1), box-shadow .35s cubic-bezier(.2, .8, .2, 1); }
.glass:hover, .glass:focus-visible { transform: translateY(-6px); }

A highlight that sweeps across

A bright band moving across the glass is the most recognisable glass interaction. Gradients cannot be transitioned directly, but a registered custom property can. Register --sheen as a percentage with @property, use it as a gradient stop, and transition the property.

@property --sheen {
  syntax: '<percentage>';
  inherits: false;
  initial-value: -30%;
}

.glass::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(105deg,
    transparent calc(var(--sheen) - 18%),
    rgba(255, 255, 255, .28) var(--sheen),
    transparent calc(var(--sheen) + 18%));
  transition: --sheen .9s cubic-bezier(.4, 0, .2, 1);
}

.glass:hover::before,
.glass:focus-visible::before { --sheen: 130%; }

Without @property the browser treats --sheen as a plain token and swaps it instantly, so the band jumps instead of sliding. Registered custom properties work in all current major browsers; in an older one the effect simply snaps, which is a fine fallback.

Here is how the demo's motion is timed:

PartPropertyDurationEasing
Card lifttransform: translateY(0 → -6px)350 mscubic-bezier(.2, .8, .2, 1)
Shadowbox-shadow350 mscubic-bezier(.2, .8, .2, 1)
Sheen--sheen: -30% → 130%900 mscubic-bezier(.4, 0, .2, 1)
Background blobstransform10 to 15 s, alternateease-in-out

Contrast and legibility

This is where most glass designs fail. The text sits on a surface whose colour depends on what is behind it, and that changes as the page scrolls or the background moves. WCAG asks for a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text, and that has to hold at the worst moment, not the average one.

  • Test against the brightest backdrop. Move the panel over the lightest, busiest part of the background and check the text there. With white text, a bright yellow or orange blob behind a thin white tint is usually the failing case.
  • Add a dark tint under the light one. The base CSS above layers a faint rgba(17, 19, 24, .28) beneath the white gradient. It barely changes the look, but it keeps white text readable over bright colours.
  • More blur helps contrast. Blur averages the background, so sharp light-dark edges behind letters disappear.
  • Do not rely on text-shadow. It helps a little, but contrast checkers ignore it, and it makes small text look smudged.
  • Keep glass for chrome, not long reading. Navigation bars, cards, chips and dialogs work well. Paragraphs of body text belong on a solid surface.

A fallback for browsers without backdrop-filter

Support for backdrop-filter is broad in current browsers, but it can be missing in older ones and in some embedded browsers. Without it, a 16 percent white fill over colour is unreadable. Use a feature query to swap in a near-solid fill:

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: rgba(28, 31, 38, .92); }
}

Also check that no ancestor of the glass element has a filter, a mask, mix-blend-mode or opacity below 1. Those can turn the ancestor into the boundary the blur is allowed to see, so the glass blurs only the ancestor's own contents and the page behind looks unblurred. The same rule is why glass nested inside another glass panel often looks flat.

Performance

backdrop-filter is one of the more expensive things you can put on a page. The cost grows with the blurred area and the blur radius, and the browser has to redo the work whenever anything behind the panel changes.

  • Avoid full-screen glass over video or constant animation. A sticky glass navbar over a scrolling page is fine; a full-viewport glass overlay over a looping video will drop frames on phones.
  • Keep the number of glass panels on screen small, and keep the blur radius at the lowest value that looks right.
  • Never transition backdrop-filter on large elements. Fade a pre-blurred panel in with opacity instead.
  • Test on a mid-range Android phone, not only on a desktop GPU. That is where the cost shows first.

Reduced motion

The glass itself is static, so it stays as it is. What changes under prefers-reduced-motion: reduce is everything that moves: stop the background blobs, drop the lift, and disable the sheen. The reduced motion guide covers the pattern in more detail.

@media (prefers-reduced-motion: reduce) {
  .bg-blob { animation: none; }
  .glass, .glass::before { transition: none; }
  .glass:hover, .glass:focus-visible { transform: none; }
}

Any looping background behind glass that runs longer than five seconds also needs a pause control, like the button in the demo.

Start from a working example

If you have seen a glass card with a hover you like, you can measure it instead of guessing. The Capture Motion Chrome extension records the lift, shadow and highlight timing while the hover plays, using a real :hover state (see how to capture hover animations), and exports CSS, React, GSAP or JSON. The blur and fill values are static styles, so read those from the element's computed styles in DevTools. You can also browse the gallery for animated components to play with and customize before copying them.

Questions

Why does my backdrop-filter not show any blur?

The element needs a background that is at least partly transparent, and there has to be something colourful behind it to blur. Also check that no ancestor has a filter, a mask or opacity below 1, which can stop the blur from seeing the page behind it.

Is glassmorphism bad for accessibility?

Only when text sits on a fill that is too light over a background that changes. Check contrast against the brightest and the busiest part of the backdrop, raise the tint or blur until normal text reaches 4.5:1, and provide a solid fallback.

Can I animate the blur amount?

You can, but changing the blur radius means the browser re-blurs the area on every frame, which is expensive on large panels and weak devices. Animate transform, opacity or a highlight layer instead and keep the blur fixed.

How do I copy a glass hover effect I saw on another site?

Use the Capture Motion Chrome extension. It sets a real :hover state on the element through the Chrome DevTools Protocol, records every animated property with its duration, delay and easing, and exports CSS, React, GSAP or JSON.