Liquid Glass
液态玻璃
A rounded glass surface bends the scene behind it as a highlight glides across the glass.
Where to use it
Add depth to navigation bars, buttons, and floating panels. Test the strongest refraction over both light and dark areas. Keep labels above the refracted layer.
Practical example
A photo editor floats its crop toolbar over the canvas. The photo bends at the glass rim while tool labels stay sharp.
Also called
- Liquid Glassmorphism
AI prompt
Add Liquid Glass to [target]. The surface is rounded, semi-transparent, and refracts the background with a moving specular highlight. Keep text sharp. For reduced motion, keep refraction but freeze the highlight.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Liquid Glass</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.demo { position: relative; padding: 0; }
.showcase { position: absolute; inset: 0; isolation: isolate; overflow: hidden; }
.showcase .demo-button {
position: absolute;
z-index: 3;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
border-radius: 999px;
background: #101026d9;
color: #f1efff;
white-space: nowrap;
}
.showcase :is(h1, p) { margin: 0; }
.scene-copy {
position: absolute;
z-index: 1;
inset: 0;
display: grid;
place-content: center;
padding: 14px;
text-align: center;
pointer-events: none;
}
.scene-copy h1 {
font-size: clamp(25px, 8vw, 62px);
line-height: 1;
letter-spacing: -.045em;
}
.showcase [data-motion] { animation-play-state: paused; }
.showcase[data-playing] [data-motion] { animation-play-state: running; }
@media (prefers-reduced-motion: reduce) {
.showcase [data-motion] { animation: none; }
.showcase [data-loop-toggle] { display: none; }
}
.showcase { background: #2b2758; }
.glass-field { position: absolute; inset: 0; overflow: hidden; }
.glass-art {
position: absolute;
inset: 50% auto auto 50%;
width: 100vw;
height: 100vh;
transform: translate(-50%, -50%);
background:
repeating-linear-gradient(135deg, #ffffff19 0 1px, transparent 1px 15px),
radial-gradient(ellipse at 7% 30%, #4c71dc, transparent 52%),
radial-gradient(ellipse at 89% 85%, #ff9e9b 0, #a868ed 55%, #382f75 100%);
}
.glass-loop {
position: absolute;
top: 21%; left: -9%; width: 118%; height: 58%;
border: clamp(13px, 5vw, 30px) solid #5ee1de;
border-radius: 50%;
transform: rotate(-30deg);
box-shadow: inset 0 4px 11px #155b9a, 0 7px 24px #24215764;
}
.glass-loop-light {
top: 21%; left: 19%; width: 69%; height: 60%;
transform: rotate(48deg);
border-color: #f5d594;
box-shadow: inset 0 4px 10px #fc8db2, 0 6px 19px #59337277;
}
.glass-lens {
position: absolute;
inset: 50% auto auto 50%;
display: grid;
width: clamp(137px, 50vw, 300px);
height: clamp(72px, 41vh, 157px);
place-items: center;
isolation: isolate;
overflow: hidden;
transform: translate(-50%, -50%);
border: 1px solid #ffffffb3;
border-radius: clamp(24px, 8vw, 54px);
box-shadow: 0 12px 27px #26234d7d, 0 2px 9px #130f2952;
}
.glass-refraction, .glass-glint { position: absolute; z-index: -1; inset: 0; }
.glass-refraction { background: #58427655; }
.glass-refraction .glass-art {
filter: url(#lens-refraction);
transform: translate(-50%, -50%) scale(1.15);
}
.glass-glint {
background:
linear-gradient(125deg, #ffffff99, transparent 27%, transparent 55%, #ffffff86 68%, transparent 81%) 28% 0 / 185% 100%,
linear-gradient(#1e164e2b, #201b593d);
box-shadow:
inset 0 2px 4px #fff9, inset 0 -3px 8px #dbdeffb3,
inset 2px 0 10px #d5f4ff9c, inset -3px 0 11px #472b854d;
animation: lens-light 6s ease-in-out infinite alternate;
}
.glass-lens h1 {
font-size: clamp(25px, 8vw, 52px);
font-weight: 640;
letter-spacing: -.05em;
color: #fff;
text-shadow: 0 1px 5px #1a174f, 0 1px 14px #2a235c;
}
.glass-defs { position: absolute; }
@keyframes lens-light { to { background-position: 99% 0, 0 0; } }
</style>
</head>
<body>
<main class="demo">
<div class="showcase">
<div class="glass-field" aria-hidden="true"><div class="glass-art">
<i class="glass-loop"></i><i class="glass-loop glass-loop-light"></i>
</div></div>
<div class="glass-lens">
<div class="glass-refraction" aria-hidden="true"><div class="glass-art">
<i class="glass-loop"></i><i class="glass-loop glass-loop-light"></i>
</div></div>
<div class="glass-glint" data-motion aria-hidden="true"></div>
<h1>Prism</h1>
</div>
<svg class="glass-defs" width="0" height="0" aria-hidden="true">
<filter id="lens-refraction" x="-15%" y="-15%" width="130%" height="130%">
<feTurbulence type="fractalNoise" baseFrequency=".012 .025" numOctaves="1" seed="9" result="lens-map"/>
<feDisplacementMap in="SourceGraphic" in2="lens-map" scale="32" xChannelSelector="R" yChannelSelector="G"/>
</filter>
</svg>
<button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">Play demo</button>
</div>
</main>
<script>
const showcase = document.querySelector('.showcase');
const toggle = showcase.querySelector('[data-loop-toggle]');
const preference = matchMedia('(prefers-reduced-motion: reduce)');
let playing = false;
function syncPlayback() {
if (preference.matches) playing = false;
const active = playing && !document.hidden;
showcase.toggleAttribute('data-playing', active);
toggle.textContent = playing ? "Pause demo" : "Play demo";
}
toggle.addEventListener('click', () => {
playing = !playing;
syncPlayback();
});
preference.addEventListener('change', syncPlayback);
document.addEventListener('visibilitychange', syncPlayback);
</script>
</body>
</html>Original example by UI Skills