Tutorials
Liquid Glass Button in CSS: Hover, Pressed and Focus States (Copy-Paste)
A production-ready liquid glass button in HTML and CSS: frosted base, specular rim, real edge refraction, springy hover and pressed states, a visible focus ring, a primary variant and accessibility fallbacks.

In short: A liquid glass button in CSS is a real button with a translucent background, a backdrop blur, a gradient rim and an SVG lens for Chromium browsers. Give it hover, pressed, focus and disabled states, and respect reduced motion and reduced transparency.
Buttons are where liquid glass works best. They’re small, so the effect is cheap to render. They float above content, which is exactly where Apple’s guidelines say glass belongs. And because people touch them, the material’s reaction to hover and press sells the illusion better than any static card.
This tutorial builds a complete liquid glass button with every state a real interface needs. We tested the final code in Chromium. All snippets are plain CSS: no framework, no JavaScript apart from one optional line of browser detection.
The anatomy of a liquid glass button
| Part | Purpose | Technique |
|---|---|---|
| Surface | Translucent body that frosts and saturates the background | background + backdrop-filter |
| Rim light | Thin gradient edge, lit from one corner | Masked ::before |
| Inner glow | Soft light pooling at the top, stronger on hover | Radial gradient on ::after |
| Lens | Background bends at the rounded ends | SVG displacement filter (Chromium) |
| Motion | Lifts on hover, sinks when pressed, springs back | transform with a springy easing curve |
| Focus | Clear keyboard indicator | :focus-visible outline |
The HTML
Use a real <button> (or an <a> for navigation). Never use a <div> with a click handler: you would lose keyboard support, focus and screen reader semantics.
<button class="glass-btn" type="button">Get started</button>
<button class="glass-btn glass-btn--primary" type="button">Download</button>
Step 1: the surface, rim and glow
This part works in every modern browser and is the version Safari and Firefox users will see, so it has to look finished on its own.
.glass-btn {
--tint: 255 255 255;
position: relative;
isolation: isolate;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 10px;
min-height: 48px;
padding: 0 28px;
border: 0;
border-radius: 999px;
font: 600 16px/1 system-ui, sans-serif;
color: #fff;
text-shadow: 0 1px 2px rgb(0 0 0 / .25);
background: rgb(var(--tint) / .14);
-webkit-backdrop-filter: blur(10px) saturate(170%);
backdrop-filter: blur(10px) saturate(170%);
box-shadow:
inset 0 1px 0 rgb(255 255 255 / .6),
inset 0 -1px 0 rgb(255 255 255 / .15),
0 6px 18px rgb(0 0 0 / .22);
cursor: pointer;
transition:
transform .35s cubic-bezier(.34, 1.56, .64, 1),
background-color .25s ease,
box-shadow .25s ease;
}
.glass-btn::before {
content: "";
position: absolute;
inset: 0;
z-index: -1;
border-radius: inherit;
padding: 1.5px;
background: linear-gradient(135deg, rgb(255 255 255 / .85), transparent 45% 55%, rgb(255 255 255 / .4));
-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);
pointer-events: none;
}
.glass-btn::after {
content: "";
position: absolute;
inset: 0;
z-index: -1;
border-radius: inherit;
background: radial-gradient(120% 90% at 50% 0%, rgb(255 255 255 / .35), transparent 60%);
opacity: .6;
transition: opacity .25s ease;
pointer-events: none;
}
Why these choices:
isolation: isolatecreates a stacking context, so the pseudo-elements withz-index: -1stay behind the label but inside the button.--tintholds the glass colour as RGB channels, so each variant changes one variable instead of five declarations.- The rim gradient leaves its middle transparent (
transparent 45% 55%), so light only catches two opposite corners, as on a real bevel. min-height: 48pxkeeps the touch target comfortable on phones.
Step 2: the lens (refraction for Chromium)
Add the SVG filter once per page, anywhere in <body>. The map is shaped like a pill: neutral grey in the middle, red and green gradients towards the rounded ends:
<svg width="0" height="0" style="position:absolute" aria-hidden="true" focusable="false">
<filter id="btn-lens" x="0" y="0" width="1" height="1"
primitiveUnits="objectBoundingBox" color-interpolation-filters="sRGB">
<feImage x="0" y="0" width="1" height="1" preserveAspectRatio="none" result="map"
href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 240 64' preserveAspectRatio='none'%3E%3Cdefs%3E%3ClinearGradient id='x'%3E%3Cstop offset='0' stop-color='rgb(64,0,0)'/%3E%3Cstop offset='1' stop-color='rgb(191,0,0)'/%3E%3C/linearGradient%3E%3ClinearGradient id='y' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='rgb(0,0,0)'/%3E%3Cstop offset='1' stop-color='rgb(0,255,0)'/%3E%3C/linearGradient%3E%3Cfilter id='b'%3E%3CfeGaussianBlur stdDeviation='5'/%3E%3C/filter%3E%3C/defs%3E%3Crect width='240' height='64' rx='32' fill='url(%23x)'/%3E%3Crect width='240' height='64' rx='32' fill='url(%23y)' style='mix-blend-mode:screen'/%3E%3Crect x='18' y='14' width='204' height='36' rx='18' fill='rgb(128,128,128)' filter='url(%23b)'/%3E%3C/svg%3E"/>
<feDisplacementMap in="SourceGraphic" in2="map" scale="-0.22"
xChannelSelector="R" yChannelSelector="G"/>
</filter>
</svg>
Then add a class to <html> in Chromium browsers and apply the lens under it:
<script>
if (navigator.userAgentData?.brands?.some(b => b.brand === 'Chromium')) {
document.documentElement.classList.add('lg-refract');
}
</script>
.lg-refract .glass-btn {
-webkit-backdrop-filter: url(#btn-lens) blur(1.5px) saturate(170%);
backdrop-filter: url(#btn-lens) blur(1.5px) saturate(170%);
}
The blur drops to 1.5px when the lens is active. Through clear glass the bend is visible, and through heavy frost it isn’t. To make the effect stronger, change scale="-0.22" to -0.3. For a softer effect, use -0.12. How the map works is explained in the liquid glass CSS guide.
Step 3: hover, pressed, focus and disabled
States make a button feel like an object. The hover lift uses cubic-bezier(.34, 1.56, .64, 1), a curve that overshoots slightly and settles, like a spring. The pressed state gets a much shorter transition, so a click feels immediate:
.glass-btn:hover {
transform: translateY(-2px) scale(1.03);
background: rgb(var(--tint) / .2);
box-shadow:
inset 0 1px 0 rgb(255 255 255 / .75),
inset 0 -1px 0 rgb(255 255 255 / .2),
0 10px 26px rgb(0 0 0 / .28);
}
.glass-btn:hover::after { opacity: 1; }
.glass-btn:active {
transform: translateY(0) scale(.97);
transition-duration: .1s;
box-shadow:
inset 0 2px 6px rgb(0 0 0 / .25),
inset 0 -1px 0 rgb(255 255 255 / .2),
0 3px 10px rgb(0 0 0 / .2);
}
.glass-btn:focus-visible {
outline: 2px solid #fff;
outline-offset: 4px;
}
.glass-btn:disabled {
opacity: .5;
cursor: not-allowed;
transform: none;
}
| State | What changes | Why |
|---|---|---|
| Hover | Lifts 2px, grows 3%, brighter rim and glow, deeper shadow | The glass rises toward the light |
| Pressed | Sinks below rest, inner shadow at the top | Physical feedback that the press registered |
| Focus | 2px white outline with a 4px offset | Keyboard users must always see where they are |
| Disabled | Half opacity, no motion | Clearly unavailable without disappearing |
Don’t remove the focus outline to keep the glass “clean”. It’s an accessibility requirement (WCAG 2.4.7), and an offset ring looks deliberate on glass anyway.
Step 4: a coloured primary variant
Because the colour lives in --tint, a primary button is two short rules. Use a higher alpha than the neutral button: tinted glass needs more of its own colour to read as a call to action:
.glass-btn--primary {
--tint: 64 132 255;
background: rgb(var(--tint) / .55);
}
.glass-btn--primary:hover { background: rgb(var(--tint) / .65); }
On light backgrounds, flip the scheme: a dark tint with white text (--tint: 15 18 28 at about 0.6), or a white tint at 0.7 with near-black text. Always check the label’s contrast against the busiest part of the background. Our accessible glass UI guide explains how.
Step 5: respect user preferences
@media (prefers-reduced-motion: reduce) {
.glass-btn, .glass-btn::after { transition: none; }
.glass-btn:hover, .glass-btn:active { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
.glass-btn, .lg-refract .glass-btn {
background: rgb(28 30 40 / .92);
-webkit-backdrop-filter: none;
backdrop-filter: none;
}
}
@media (forced-colors: active) {
.glass-btn { border: 1px solid ButtonText; }
}
These rules turn off the motion for people who get motion sickness, replace transparency with a solid surface for those who asked the OS for it, and draw a real border in Windows High Contrast mode, where backgrounds and shadows are removed.
Icon buttons
For a round icon button, reuse the class and override the shape. Give it an accessible name, because an icon alone isn’t announced by screen readers:
<button class="glass-btn glass-btn--icon" type="button" aria-label="Play">
<svg width="20" height="20" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M8 5v14l11-7z"/></svg>
</button>
.glass-btn--icon {
width: 48px;
padding: 0;
}
For perfectly round buttons, use a displacement map drawn as a circle instead of a pill, or generate one in the builder by choosing the Icon button component.
Common mistakes
- Too much blur. Glass with 25px blur is just a grey pill. Use 6–12px for the fallback and 0–3px with refraction.
- No tint on busy backgrounds. White text over a bright photo with a 5% tint fails contrast. Raise the tint until the label passes 4.5:1.
- Animating
backdrop-filter. It forces expensive repaints on every frame. Animatetransform,opacityandbox-shadow. - Different light angles per component. Keep the rim gradient angle the same on every glass element of a page.
- Glass buttons over a plain colour. Glass needs something behind it to bend. Over a flat colour it looks like a semi-transparent pill, so use a solid button there instead.
Frequently asked questions
How do I make a liquid glass button in CSS?
Combine a translucent background, backdrop-filter: blur() saturate(), a gradient rim on ::before and inset highlights. For real liquid glass, add an SVG feDisplacementMap filter applied with backdrop-filter: url(#filter) in Chromium browsers. The full code is above.
Does the liquid glass button work in Safari?
Yes, as frosted glass with the rim, glow and all states. Safari doesn’t render SVG filters inside backdrop-filter, so the lens is skipped there. That’s why the detection class matters.
How do I make the glass button work on a light background?
Increase the tint alpha (0.55–0.75 white with dark text, or a dark tint with white text) and add a slightly stronger drop shadow so the button separates from the page.
Can I use this button in React or Tailwind?
Yes. The CSS is framework-agnostic: use className="glass-btn" in React and render the SVG filter once in your layout. See our liquid glass in React guide, see the Tailwind version, or export Tailwind classes from the builder.
Is a liquid glass button bad for performance?
A few buttons cost very little. Backdrop filters get expensive with large areas, many stacked layers or animated blur. A small fixed-size button is the cheapest place to use liquid glass.
Design it visually instead
Tuning tint, refraction and states by hand takes a while. The UIGlass builder gives you the same button with sliders for every value, live contrast checking and one-click export. You can also start from a ready-made design among the presets.
What CSS do I need for a glass button?
You need a translucent background, backdrop-filter: blur() saturate(), rounded corners, inset highlights with box-shadow and a gradient rim on ::before. An SVG displacement filter adds refraction in Chromium browsers.
How do I add a hover effect to a glass button?
Lift it slightly with transform: translateY(-2px) scale(1.03), brighten the tint and rim, deepen the shadow, and use a springy easing such as cubic-bezier(.34, 1.56, .64, 1).
How do I make a glass icon button accessible?
Use a real <button>, give it an aria-label such as “Play”, hide the icon from screen readers with aria-hidden="true", keep a visible focus ring and make it at least 44 to 48 pixels in size.
Should a liquid glass button use a div or a button element?
Always use a <button> for actions and an <a> for navigation. A clickable div loses keyboard support, focus and screen reader semantics.


