CSS Glassmorphism Card
CSS glassmorphism with backdrop-filter: blur() saturate(), a dark tint for contrast, and a light edge. The blur softens vivid colors.
- Level
- Beginner
- Published
- Updated
- Reading time
- 7 min
Try it
4 live demos
Glass card
Frosted glass
A blur, a thin tint and a bright edge. The color behind stays, only softer.
Frosted glass over moving color
Other ways to build it
A glass sign-in form
See the codeBack
blur 4px, tint .45
Middle
blur 10px, tint .5
Front
blur 22px, tint .55
Stacked panels for depth
See the codeDark tint
Smoked glass
White text on a dark fill. Safe over the brightest color.
Light tint
Milky glass
Dark text on a white fill. Safe over the darkest color.
Dark tint and light tint
See the codeBuild it
8 snippets to copy
CSS Glassmorphism Card
HTML
<div class="gm-scene">
<span class="gm-orb gm-orb-1"></span>
<span class="gm-orb gm-orb-2"></span>
<span class="gm-orb gm-orb-3"></span>
<div class="gm-card">
<p class="gm-kicker">Glass card</p>
<p class="gm-title">Frosted glass</p>
<p class="gm-text">A blur, a thin tint and a bright edge. The color behind stays, only softer.</p>
<ul class="gm-tags">
<li>blur 16px</li>
<li>saturate 180%</li>
</ul>
</div>
</div>
CSS
/* a fixed, vivid scene: glass only reads over strong color */
.gm-scene {
position: relative;
isolation: isolate;
display: grid;
place-items: center;
width: min(100%, 34rem);
height: 22rem;
overflow: hidden;
border-radius: 18px;
background: linear-gradient(140deg, #1b1446, #2a1060 55%, #3d0f4f);
}
/* hard-edged shapes, so the glass edge shows sharp
outside and soft inside */
.gm-orb {
position: absolute;
z-index: -1;
border-radius: 50%;
animation: gm-drift var(--gm-time, 16s) ease-in-out infinite alternate;
}
.gm-orb-1 {
top: -2rem;
left: 8%;
width: 12rem;
height: 12rem;
background: linear-gradient(135deg, #ff5fa2, #c026d3);
--gm-dx: 4rem;
--gm-dy: 3rem;
}
.gm-orb-2 {
right: 6%;
bottom: -2.5rem;
width: 10rem;
height: 10rem;
background: linear-gradient(135deg, #ffc247, #ff5e3a);
--gm-dx: -5rem;
--gm-dy: -3rem;
--gm-time: 19s;
}
.gm-orb-3 {
top: 18%;
right: 12%;
width: 6rem;
height: 6rem;
background: linear-gradient(135deg, #3ee0ff, #3b6bff);
--gm-dx: -3rem;
--gm-dy: 5rem;
--gm-time: 13s;
}
@keyframes gm-drift {
to { translate: var(--gm-dx) var(--gm-dy); }
}
/* the glass: a tint dark enough for white text, a white
sheen on top, the blur behind, and an edge lit from above */
.gm-card {
position: relative;
width: min(84%, 19rem);
padding: 1.4rem 1.5rem 1.5rem;
border: 1px solid rgba(255, 255, 255, .28);
border-top-color: rgba(255, 255, 255, .55);
border-radius: 20px;
color: #fff;
background:
linear-gradient(150deg, rgba(255, 255, 255, .16), rgba(255, 255, 255, .04) 60%),
rgba(18, 12, 44, .5);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, .35),
0 1.2rem 2.5rem rgba(8, 4, 28, .45);
-webkit-backdrop-filter: blur(16px) saturate(180%);
backdrop-filter: blur(16px) saturate(180%);
}
.gm-kicker {
margin: 0;
font-size: .72rem;
font-weight: 700;
letter-spacing: .12em;
text-transform: uppercase;
}
.gm-title {
margin: .35rem 0 .5rem;
font-size: 1.55rem;
font-weight: 800;
line-height: 1.15;
}
.gm-text {
margin: 0;
font-size: .92rem;
line-height: 1.55;
}
.gm-tags {
display: flex;
flex-wrap: wrap;
gap: .4rem;
margin: 1rem 0 0;
padding: 0;
list-style: none;
}
.gm-tags li {
padding: .25rem .6rem;
border: 1px solid rgba(255, 255, 255, .3);
border-radius: 99px;
font-family: monospace;
font-size: .72rem;
background: rgba(18, 12, 44, .3);
}
/* no blur at all: a nearly solid tint keeps the text
readable. Test both spellings, or a browser with only
the prefixed one would lose its blur to the fallback. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
.gm-card {
background: rgba(24, 16, 56, .92);
}
}
@media (prefers-reduced-motion: reduce) {
.gm-orb {
animation: none;
}
}
A glass sign-in form
The same blur and tint treatment applied to a login form, with glass inputs and one solid button so the action is never in doubt. The fields have a darker tint than the card itself, the placeholders are slightly transparent white, and the submit button is opaque white with dark text. method="dialog" on a form outside a <dialog> submits nowhere, so the demo can be filled and submitted without leaving the page. A real form needs its own action. Pick this when you need a login or signup panel on a hero image or bright brand background.
HTML
<div class="gm-scene gm-scene-form">
<span class="gm-orb gm-orb-1"></span>
<span class="gm-orb gm-orb-2"></span>
<span class="gm-orb gm-orb-3"></span>
<!-- method="dialog" outside a dialog submits nowhere;
give a real form its own action -->
<form class="gm-card gm-form" method="dialog" aria-label="Sign in">
<p class="gm-title">Sign in</p>
<label class="gm-field">Email
<input type="email" name="email" placeholder="name@example.com" autocomplete="off" required>
</label>
<label class="gm-field">Password
<input type="password" name="password" placeholder="Your password" autocomplete="off" required>
</label>
<button class="gm-btn" type="submit">Sign in</button>
</form>
</div>
CSS
/* adds to the main example: .gm-scene, .gm-orb, .gm-card
and .gm-title come from there */
.gm-scene-form {
height: 27rem;
}
.gm-form {
display: grid;
gap: .9rem;
}
.gm-form .gm-title {
margin: 0 0 .1rem;
}
.gm-field {
display: grid;
gap: .35rem;
font-size: .85rem;
font-weight: 600;
}
/* the fields are glass too: a darker tint, a light edge */
.gm-field input {
width: 100%;
box-sizing: border-box;
padding: .65rem .8rem;
border: 1px solid rgba(255, 255, 255, .32);
border-radius: 10px;
font: inherit;
font-weight: 400;
color: #fff;
background: rgba(18, 12, 44, .55);
}
.gm-field input::placeholder {
color: rgba(255, 255, 255, .8);
}
/* one solid control, so the action is never in doubt */
.gm-btn {
margin-top: .35rem;
padding: .7rem 1rem;
border: 0;
border-radius: 10px;
font: inherit;
font-weight: 700;
color: #1b1446;
background: #fff;
cursor: pointer;
}
.gm-btn:hover {
background: rgba(255, 255, 255, .85);
}
.gm-field input:focus-visible,
.gm-btn:focus-visible {
outline: 2px solid #fff;
outline-offset: 2px;
}
Stacked panels for depth
Three glass panels as siblings, not nested, each with its own blur level: 4px on the back, 10px in the middle, 22px up front. The front panel blurs the panels behind it as well as the orbs, which is what creates the sense of depth. Each layer also gets a different tint opacity and sheen strength, so nearer surfaces feel thicker. The panels are siblings rather than nested because a backdrop-filter inside another filtered element only sees its parent's surface, not the original scene. Pick this for a dashboard or layered UI where closer surfaces should look denser and softer.
HTML
<div class="gm-scene">
<span class="gm-orb gm-orb-1"></span>
<span class="gm-orb gm-orb-2"></span>
<span class="gm-orb gm-orb-3"></span>
<div class="gm-stack">
<div class="gm-card gm-layer gm-layer-back">
<p class="gm-layer-name">Back</p>
<p class="gm-layer-spec">blur 4px, tint .45</p>
</div>
<div class="gm-card gm-layer gm-layer-mid">
<p class="gm-layer-name">Middle</p>
<p class="gm-layer-spec">blur 10px, tint .5</p>
</div>
<div class="gm-card gm-layer gm-layer-front">
<p class="gm-layer-name">Front</p>
<p class="gm-layer-spec">blur 22px, tint .55</p>
</div>
</div>
</div>
CSS
/* adds to the main example: .gm-scene, .gm-orb and .gm-card
come from there. The panels are siblings, never nested:
a backdrop-filter inside another one sees only its parent. */
.gm-stack {
position: relative;
width: min(88%, 22rem);
height: 16.5rem;
}
/* each layer sets its own blur and tint: further back is
clearer and thinner, nearer is softer and denser */
.gm-layer {
position: absolute;
width: 72%;
height: 8.5rem;
padding: .9rem 1rem;
box-sizing: border-box;
background:
linear-gradient(150deg, rgba(255, 255, 255, var(--gm-sheen)), rgba(255, 255, 255, 0) 60%),
rgba(18, 12, 44, var(--gm-tint));
-webkit-backdrop-filter: blur(var(--gm-blur)) saturate(180%);
backdrop-filter: blur(var(--gm-blur)) saturate(180%);
}
.gm-layer-back {
top: 0;
left: 0;
--gm-blur: 4px;
--gm-tint: .45;
--gm-sheen: .06;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 .5rem 1rem rgba(8, 4, 28, .3);
}
.gm-layer-mid {
top: 4rem;
left: 14%;
--gm-blur: 10px;
--gm-tint: .5;
--gm-sheen: .12;
}
.gm-layer-front {
top: 8rem;
left: 28%;
--gm-blur: 22px;
--gm-tint: .55;
--gm-sheen: .2;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 1.6rem 3rem rgba(8, 4, 28, .55);
}
.gm-layer-name {
margin: 0;
font-weight: 800;
}
.gm-layer-spec {
margin: .2rem 0 0;
font-family: monospace;
font-size: .72rem;
}
Dark tint and light tint
Two cards side by side showing the two ways to make glassmorphism text readable. The dark tint uses white text on a dark violet fill, safe over the brightest colors in the scene. The light tint flips it: dark text on a milky white fill, safe over the darkest parts or over busy patterns where a dark card would get lost. Both keep text readable over the bright gradients. Pick the dark tint with white text for bright, saturated art or video backgrounds, and the light tint with dark text for dark scenes, muted backgrounds, or a light UI.
HTML
<div class="gm-scene gm-scene-pair">
<span class="gm-orb gm-orb-1"></span>
<span class="gm-orb gm-orb-2"></span>
<span class="gm-orb gm-orb-3"></span>
<div class="gm-pair">
<div class="gm-card">
<p class="gm-kicker">Dark tint</p>
<p class="gm-title">Smoked glass</p>
<p class="gm-text">White text on a dark fill. Safe over the brightest color.</p>
<ul class="gm-tags"><li>rgba(18, 12, 44, .5)</li></ul>
</div>
<div class="gm-card gm-light">
<p class="gm-kicker">Light tint</p>
<p class="gm-title">Milky glass</p>
<p class="gm-text">Dark text on a white fill. Safe over the darkest color.</p>
<ul class="gm-tags"><li>rgba(255, 255, 255, .55)</li></ul>
</div>
</div>
</div>
CSS
/* adds to the main example: the dark card is .gm-card as it
is there; only the light one is new */
.gm-scene-pair {
width: min(100%, 40rem);
height: auto;
min-height: 22rem;
padding: 2.5rem 0;
box-sizing: border-box;
}
.gm-pair {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr));
gap: 1.25rem;
width: 90%;
}
.gm-pair .gm-card {
width: auto;
}
/* the light tint flips the text: dark ink on a milky fill */
.gm-light {
border-color: rgba(255, 255, 255, .6);
border-top-color: rgba(255, 255, 255, .9);
color: #17112f;
background:
linear-gradient(150deg, rgba(255, 255, 255, .25), rgba(255, 255, 255, 0) 60%),
rgba(255, 255, 255, .55);
}
.gm-light .gm-tags li {
border-color: rgba(23, 17, 47, .3);
background: rgba(255, 255, 255, .35);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
.gm-light {
background: rgba(255, 255, 255, .92);
}
}
Understand it
How it works and 7 properties
Glassmorphism is a frosted glass effect built from backdrop-filter, a translucent fill, and a fine light edge. The filter blurs and saturates whatever sits behind the element, the fill controls how much shows through, and the edge catches the light. Put it over something vivid and the colors stay visible but softer, which is where the glass look comes from.
The hard part is contrast. A white fill with white text produces a low contrast ratio over bright backgrounds, so the readable version uses a dark tint instead. The demo below picks its tint opacity to keep white text legible, and the variants show a glass form, stacked panels at different blur depths, and the light tint version with dark text. CSS frosted nav applies the same filter to a scrolling bar, and CSS liquid glass bends the backdrop with an SVG displacement map.
How it works
The card sits over three slow-moving gradient circles on a dark stage. backdrop-filter: blur(16px) saturate(180%) softens the shapes behind the card and pumps up their color, and the dark violet tint at 50% opacity keeps the white text readable over even the brightest part of the pink circle. The sheen is a white-to-transparent gradient layered over the tint, the border is brighter at the top as if lit from above, and an inset highlight along the top edge finishes the glass treatment. isolation: isolate on the scene keeps the orbs visible at z-index: -1 above the scene's own background.
The tint opacity is the number that decides whether this works. A classic glassmorphism card uses a white fill at low opacity, and white text over that produces a contrast ratio around 1.8 over this same vivid background. A dark tint at 30% opacity with the same sheen produces 3.8. The version here uses a dark violet tint at 50% opacity, and the white text measures 5.3 at its worst against the drifting circles. Readable glassmorphism over bright color uses a tinted glass with light text, or the inverse shown in the variant pair.
The orbs drift at three different periods, 16, 19, and 13 seconds, which do not line up, so the pattern behind the card keeps changing rather than looping on a simple cycle. Each orb animates translate with ease-in-out and alternate, so it moves to its offset position and back, and the different durations mean the card never sees the same arrangement twice in the first several minutes. That movement is what keeps the demo from looking like a static picture of a blur.
saturate(180%) in the filter pushes the colors behind the card more intense, which is the part of the effect that reads as looking through thick glass rather than waxed paper. Remove it and the blur stays.
Accessibility notes
Blur changes what text looks like without changing what it is, so contrast has to be checked on the blurred and tinted result, not the authored colors. A stylesheet that writes white text over a dark tint will pass an automated check, but if the blur is applied over a bright photo and the tint is too faint, the rendered text can be unreadable. Measure contrast from the actual pixels, or avoid putting blurred treatments on body text and keep them on larger headings and decorative panels instead.
The glass form is fully operable from the keyboard. Tab from the variant reaches the email field, then the password field, then the submit button, and each shows a white outline on focus. The fields and the button are real controls with real labels. The demo form submits nowhere because method="dialog" on a form outside a <dialog> is a no-op, which keeps the page from navigating when the form is filled and submitted. A real form needs its own action.
Nothing in the main demo or the stacked panels demo takes focus or responds to interaction beyond the drifting animation, which stops under prefers-reduced-motion. The dark and light pair sits over the same drifting orbs. The blurred backdrop is a visual effect only.
Mistakes worth avoiding
- Leaving
isolation: isolateoff the container. Thez-index: -1orbs disappear behind the scene's own background, so the card blurs only the dark fill instead of the bright gradients. - Using a faint white tint with white text. It looks like glassmorphism in screenshots over dark backgrounds, but it produces a low contrast ratio over bright images or gradients.
- Theming the backdrop colors. The filter operates on real pixel values, so swapping a dark theme for a light one changes the blur result rather than recoloring it.
- Nesting blurred elements. A
backdrop-filterinside another blurred element only sees its parent's already-filtered surface, not the original backdrop, so stacking them does not add up the way you might expect. The stacked panels variant uses siblings, not children, which is why each one sees the scene and the panels behind it.
Ship it
8 features in 4 browsers, 4 questions
Browser support
| Feature | ||||
|---|---|---|---|---|
backdrop-filter | 76 | 103 | 9 | 17 |
gradients | 10 | 36 | 15.4 | 12 |
custom properties | 49 | 31 | 10 | 16 |
animation | 4 | 5 | 5.1 | 12 |
translate | 104 | 72 | 14.1 | 104 |
@supports | 28 | 22 | 9 | 12 |
:focus-visible | 86 | 4 | 15.4 | 86 |
prefers-reduced-motion | 74 | 63 | 10.1 | 79 |
Figures come from Can I Use for CSS Backdrop Filter, CSS Gradients, CSS Variables, CSS Animation, CSS translate property, CSS Feature Queries, :focus-visible pseudo-class, and prefers-reduced-motion media query. The Safari 9 figure for backdrop-filter is a prefixed first version. Browsers without support for the filter get a nearly opaque tint instead through an @supports block, which keeps the text readable but loses the blur. The -webkit- prefix appears for backdrop-filter because support began there, and the @supports test checks both spellings to avoid applying the fallback in a browser that only has the prefixed property.
What you can build with it
- Login and signup modals. A glass form over a hero image or video background, which is the sign-in variant. The blur softens the image enough to keep the fields readable without needing a solid panel.
- Feature cards on a colored page. Cards that sit over a gradient or illustration and let the background show through softly, the way the main demo does.
- Overlays and drawers. A frosted sheet sliding over content, such as a settings panel or a mobile menu, where the blur suggests the page is still there underneath.
- Dashboard widgets. Panels at different blur and tint levels to create depth, which is the stacked variant. Closer panels blur the ones behind them as well as the background.
- Notification toasts. Small glass cards that appear over the page temporarily, readable over whatever happens to be behind them because the blur and tint are chosen for contrast.
Frequently asked questions
How do you make a glassmorphism effect in CSS?
backdrop-filter: blur() saturate() to soften and intensify the colors behind an element, a translucent background to control how much shows through, and a light border to catch the edge. The readable version over bright backgrounds uses a dark tint with light text, not a faint white fill. Add isolation: isolate to the container to keep z-index: -1 backdrop elements visible above the container's own background.Why is my backdrop-filter not working?
z-index backdrop elements are not disappearing behind their container's own background. Add isolation: isolate to the wrapper. Another cause is the browser not supporting the property, in which case an @supports block can provide a fallback, such as a more opaque tint that keeps the text readable without the blur.How do I make glassmorphism text readable?
Can I theme a glassmorphism background?
backdrop-filter operates on the actual pixel colors behind the element, so theming the backdrop changes the blur result. If the effect has to survive a theme swap, pin the scene colors to fixed values the way this demo does, or build two separate versions with different tint opacities that keep contrast in each theme.