Glassmorphism in CSS: backdrop-filter, Fallbacks and Contrast
Last updated: · 6 min read
Glassmorphism is the interface style in which a panel blurs whatever lies behind it, as if seen through frosted glass. No single property creates it: backdrop-filter blurs the backdrop, a semi-transparent background colour tints it, a thin light border marks the edge of the glass and a soft shadow usually adds depth. The Glassmorphism (Glass Effect) Generator puts those four parts on sliders, previews them over a colourful background and hands you the CSS. This guide explains what backdrop-filter actually blurs, why the background has to be translucent, how to write a fallback for browsers that do not know the property and how to check text contrast on a see-through surface. The code in the example is real output from the tool.
Formula
background: rgba(R, G, B, background opacity); -webkit-backdrop-filter: blur(Npx); backdrop-filter: blur(Npx); border: 1px solid rgba(255, 255, 255, border opacity); border-radius: Kpx; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2); (optional)
backdrop-filter does not filter the element itself but the image behind it, within the element's box; blur(12px) blurs that image. As the W3C draft notes, the effect is not visible unless part of the element is semi-transparent: a fully opaque background simply covers the blurred image. That is why the background is written as rgba(); the lower the opacity, the more of the colours behind come through. The tool writes the -webkit- prefixed line before the unprefixed one because some browser versions only recognise the prefixed name. The border is always 1 px white and only its opacity changes. The shadow is a fixed value that can be switched on or off. An element with backdrop-filter creates a new stacking context and becomes the containing block for absolutely and fixed positioned descendants.
What the inputs mean
- Blur
- The blur() radius, 0–40 px. At 0 the content behind stays sharp and the panel is just a tinted translucent layer.
- Glass colour and Background opacity
- The background colour is picked as hex and the opacity set between 0 and 100 %; in the code they form one rgba() value. White suits light themes, a dark navy or black suits dark ones.
- Border opacity
- Opacity of the 1 px white border, 0–100 %. It draws a fine highlight along the edge of the glass; 0 % makes the border invisible, but the line stays in the code.
- Corner radius
- The border-radius value, 0–60 px. The blurred area is clipped to the same curve.
- Add shadow
- When ticked, the line box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2); is added. The shadow values cannot be changed in the tool; edit them in the code if needed.
Worked example: A light glass card and a second version for a dark theme
- The tool opens with: Blur 12, Background opacity 20 %, Border opacity 30 %, Corner radius 16, Glass colour #ffffff, Add shadow ticked.
- Generated code: background: rgba(255, 255, 255, 0.2); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 16px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
- In the preview the card sits over a gradient and two coloured circles; the edges of the circles blur behind the card. Drag Blur down to 0 and the circles turn sharp again, leaving only the 20 % white layer.
- Now change the values for a dark theme: Blur 16, Background opacity 45 %, Border opacity 15 %, Corner radius 20, Glass colour #0f172a, and untick Add shadow.
- Generated code: background: rgba(15, 23, 42, 0.45); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border: 1px solid rgba(255, 255, 255, 0.15); border-radius: 20px;
- With the shadow off, the box-shadow line drops out of the code; the other five lines stay in the same order.
Result: The first version gives a bright frosted pane over a colourful background; in the second, the dark background at 45 % opacity gives white text a safer contrast.
🧊 Glassmorphism CSS Generator
Free, no sign-up; your data stays in your browser.
Open the calculator →How to read the result
The effect only makes sense when there is something to blur behind it: a photo, a gradient or scrolling content. On a flat single-colour background the blur changes nothing. In a browser that does not know the property only the translucent background remains, and the text may blend into whatever is behind; so define a more opaque background first and put the translucent version inside a feature query. A hand-written example (not tool output): .card { background: rgba(15, 23, 42, 0.85); } @supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) { .card { background: rgba(15, 23, 42, 0.45); } } Check contrast not at one spot but over the lightest and the darkest content that can end up behind the panel; WCAG AA asks for at least 4.5:1 for normal text. If it falls short, raising the background opacity helps more than raising the blur. Blurring large areas or many elements at once gives the browser extra work, particularly while scrolling or animating, so keep the effect to limited surfaces such as a top bar, a card or a dialog.
Common mistakes
- Leaving the background fully opaque. background: #ffffff, or an rgba() with an alpha of 1, covers the blurred image and backdrop-filter appears to do nothing.
- Making the panel see-through with the opacity property. opacity also fades the text and the border and is applied to the filtered backdrop as well; set transparency through the alpha of the background colour only.
- Mixing up filter: blur() and backdrop-filter: blur(). filter blurs the element itself, text included; backdrop-filter blurs only what is behind it.
- Deleting the -webkit- line as redundant. In browser versions that do not recognise the unprefixed name the blur disappears and only the translucent background is left.
- Not defining a fallback background. Without backdrop-filter support, a background at 20 % opacity can leave the text unreadable.
- Checking contrast only against the background in the design file. Contrast changes as content scrolls behind the panel; test the worst case.
- Placing glass on a flat background. With no pattern or colour variation behind it the blur is invisible and what you get is an ordinary translucent box.
Frequently asked questions
Which CSS properties do I need for glassmorphism?
backdrop-filter: blur() together with a semi-transparent background does the main work. A thin light border, border-radius and a soft box-shadow emphasise the edge and depth of the glass; they are optional.
Why is backdrop-filter not working?
The three usual causes: the background is fully opaque, there is nothing behind the element to blur, or the browser does not know the property (or only knows the -webkit- prefixed name). Give the background colour an alpha value and write both lines.
What is the difference between backdrop-filter and filter?
filter applies to the element's own rendering, children included. backdrop-filter applies to the image behind the element; its text and border stay sharp.
Is glassmorphism accessible?
It needs care, because text contrast depends on what is behind the panel. The text should reach at least 4.5:1 (WCAG AA) over the lightest and the darkest background; if it does not, raise the background opacity.
Does backdrop-filter affect performance?
The backdrop has to be filtered again whenever it changes, and on large surfaces, many elements or animations that cost can be noticeable. Keep the effect to a few small surfaces and test on real devices.
Does the tool add any filter other than blur?
No, it only writes blur(). backdrop-filter accepts other filter functions on the same line, so you can extend it by hand, for example blur(12px) saturate(150%).
The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.