glassmorphism
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGlassmorphism (Frosted & Liquid Glass)
玻璃态设计(磨砂与液态玻璃效果)
Translucent, frosted UI: panels you can see through, blurred so the backdrop reads as soft color, rimmed by a bright edge of light, floating on layered shadow. The 2026 "liquid glass" evolution adds refraction — the background visibly bends through the panel — plus moving specular highlights. The goal is depth and material, not just opacity.
半透明磨砂UI:可透视的面板,背景经模糊处理呈现柔和色彩,边缘带有明亮的光边,悬浮于分层阴影之上。2026年的「液态玻璃」演进版本新增了折射效果——背景会透过面板产生明显的弯曲变形——再加上动态镜面高光。设计目标是体现深度与材质感,而非仅仅调整透明度。
When to use
适用场景
- Frosted cards, nav bars, sidebars, modals/dialogs, and toolbars over busy/photo backgrounds
- Login/hero panels and overlays that should feel layered above the page
- Apple-style "liquid glass" heroes: refracting, slowly churning surfaces with a specular sweep
- Hover/scroll/enter motion on glass — frost deepening, highlight brightening, the panel lifting
- Any place where content needs to read as floating glass while staying legible
- 在繁杂/图片背景上使用的磨砂卡片、导航栏、侧边栏、模态框/对话框及工具栏
- 需呈现为页面上层级感的登录/首屏面板与遮罩层
- 苹果风格的「液态玻璃」首屏区域:带有折射效果、缓慢流动的表面及镜面高光扫过动画
- 玻璃元素的悬停/滚动/进入动效——磨砂效果加深、高光变亮、面板抬升
- 任何需要让内容呈现为悬浮玻璃质感同时保持可读性的场景
The four ingredients of believable glass
逼真玻璃效果的四大要素
Glass is never one property. Every panel needs all four, or it reads as a plain translucent box:
- Frost — plus
backdrop-filter: blur()to keep backdrop color vivid through the blur.saturate() - Translucency — a with alpha (~0.08–0.18), never fully opaque, never fully clear.
background - Edge of glass — a hairline border brighter than the fill, ideally a lit top-left → dim bottom-right highlight, so the rim catches light.
- Depth — layered : an ambient drop shadow to float it, plus an
box-shadowtop highlight and bottom shade to round the surface.inset
css
.glass {
background: rgba(255, 255, 255, 0.12);
backdrop-filter: blur(16px) saturate(160%);
-webkit-backdrop-filter: blur(16px) saturate(160%); /* Safari needs the prefix */
border-radius: 20px;
border: 1px solid rgba(255, 255, 255, 0.25);
box-shadow:
0 8px 32px rgba(0, 0, 0, 0.25), /* float */
inset 0 1px 0 rgba(255, 255, 255, 0.35), /* top highlight */
inset 0 -1px 0 rgba(0, 0, 0, 0.12); /* bottom shade */
}Frost tiers: light UI chrome / alpha ; heavy modal/login / alpha . Dark glass: fill , softer top highlight.
blur(8–12px)0.08–0.14blur(24–40px)0.10–0.18rgba(0,0,0,0.3)backdrop-filter玻璃绝非单一属性。每个面板都需具备以下四项要素,否则只会看起来像普通的半透明盒子:
- 磨砂效果 —— 搭配
backdrop-filter: blur(),确保模糊后的背景色彩依然鲜明。saturate() - 半透明性 —— 带有alpha通道的(取值约0.08–0.18),既不完全不透明,也不完全透明。
background - 玻璃边缘 —— 一条比填充色更亮的细边框,理想状态是左上亮、右下暗的高光效果,让边缘能捕捉光线。
- 深度感 —— 分层的:用于实现悬浮效果的环境投影,加上用于模拟曲面的顶部内高光和底部内阴影。
box-shadow
css
.glass {
background: rgba(255, 255, 255, 0.12);
backdrop-filter: blur(16px) saturate(160%);
-webkit-backdrop-filter: blur(16px) saturate(160%); /* Safari needs the prefix */
border-radius: 20px;
border: 1px solid rgba(255, 255, 255, 0.25);
box-shadow:
0 8px 32px rgba(0, 0, 0, 0.25), /* float */
inset 0 1px 0 rgba(255, 255, 255, 0.35), /* top highlight */
inset 0 -1px 0 rgba(0, 0, 0, 0.12); /* bottom shade */
}磨砂层级:浅色UI控件使用 / alpha值;厚重的模态框/登录面板使用 / alpha值。深色玻璃:填充色为,顶部高光更柔和。
blur(8–12px)0.08–0.14blur(24–40px)0.10–0.18rgba(0,0,0,0.3)backdrop-filterSpecular edge highlight and anti-banding grain
镜面边缘高光与抗色带噪点
A flat border is dead. Draw a masked 1px ring with a lit corner via , and dither away gradient banding (stepped contour lines under heavy blur) with a faint noise overlay via at . Full masked-border and inline-noise recipes are in .
::beforefeTurbulence::afteropacity ≤ 0.06references/glass-recipes.md纯色边框毫无生气。通过绘制带高亮角落的遮罩1px边框,并通过添加透明度≤0.06的微弱噪点覆盖层,消除模糊效果下的渐变色带(阶梯状轮廓线)。完整的遮罩边框与内嵌噪点实现方案可查看。
::before::afterfeTurbulencereferences/glass-recipes.mdMotion: animate the glass, not the geometry
动效:为玻璃属性添加动画,而非几何形状
Animate the qualities of the glass — frost deepening, highlight brightening, the panel lifting — so it reads as the surface "leaning into the light."
css
.glass {
transition: backdrop-filter .4s ease, background .4s ease,
box-shadow .4s ease, transform .4s cubic-bezier(.16,1,.3,1);
}
.glass:hover {
backdrop-filter: blur(24px) saturate(180%);
background: rgba(255,255,255,.18);
transform: translateY(-4px);
box-shadow: 0 16px 48px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.5);
}- Entrance (frost resolving from clear): pair a transition with
[data-enter].@starting-style { backdrop-filter: blur(0); opacity: 0; transform: translateY(16px) } - Specular sweep: a skewed white gradient animated across the surface on hover or as a slow ambient loop.
- Caveat: animating the blur radius is the most expensive thing here — the backdrop is re-blurred every frame. If hover janks, animate /
transform/box-shadow(cheap) and keep the blur delta small or snap it.background
为玻璃的属性添加动画——磨砂效果加深、高光变亮、面板抬升——让它看起来像是表面「向光线倾斜」。
css
.glass {
transition: backdrop-filter .4s ease, background .4s ease,
box-shadow .4s ease, transform .4s cubic-bezier(.16,1,.3,1);
}
.glass:hover {
backdrop-filter: blur(24px) saturate(180%);
background: rgba(255,255,255,.18);
transform: translateY(-4px);
box-shadow: 0 16px 48px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.5);
}- 入场动画(从透明到磨砂效果显现):将过渡效果与
[data-enter]搭配使用。@starting-style { backdrop-filter: blur(0); opacity: 0; transform: translateY(16px) } - 镜面高光扫过:在悬停或缓慢循环动画中,让倾斜的白色渐变在表面移动。
- 注意事项:模糊半径的动画是性能开销最大的操作——每帧都要重新模糊背景。如果悬停时出现卡顿,可仅为/
transform/box-shadow(低开销属性)添加动画,并减小模糊差值或直接切换模糊状态。background
Liquid glass — SVG refraction (the 2026 look)
液态玻璃——SVG折射效果(2026年风格)
Bend the background through the panel like a thick lens: drive from animated , applied via (it distorts the element's own pixels) layered over a frost.
feDisplacementMapfeTurbulencefilterbackdrop-filterhtml
<svg width="0" height="0" style="position:absolute"><filter id="liquid-glass">
<feTurbulence type="fractalNoise" baseFrequency="0.008 0.012" numOctaves="2" seed="3" result="n">
<animate attributeName="baseFrequency" dur="18s"
values="0.008 0.012;0.012 0.008;0.008 0.012" repeatCount="indefinite"/>
</feTurbulence>
<feDisplacementMap in="SourceGraphic" in2="n" scale="22" xChannelSelector="R" yChannelSelector="G"/>
</filter></svg>scalebaseFrequencyanimatedur让背景像透过厚透镜一样穿过面板产生弯曲:通过动画驱动,并通过应用(它会扭曲元素自身的像素),叠加在磨砂效果之上。
feTurbulencefeDisplacementMapfilterbackdrop-filterhtml
<svg width="0" height="0" style="position:absolute"><filter id="liquid-glass">
<feTurbulence type="fractalNoise" baseFrequency="0.008 0.012" numOctaves="2" seed="3" result="n">
<animate attributeName="baseFrequency" dur="18s"
values="0.008 0.012;0.012 0.008;0.008 0.012" repeatCount="indefinite"/>
</feTurbulence>
<feDisplacementMap in="SourceGraphic" in2="n" scale="22" xChannelSelector="R" yChannelSelector="G"/>
</filter></svg>scalebaseFrequencyanimatedurPerformance — backdrop-filter is expensive
性能优化——backdrop-filter开销高昂
- Each glass element re-samples and blurs everything behind it. Limit the count; a dozen on screen tanks scroll FPS.
- Promote heavy glass to its own layer (or
transform: translateZ(0)), and removewill-change: transformafter the animation.will-change - Don't stack elements over each other — nested blur re-blurs the blur (quadratic cost).
backdrop-filter - Big radii (>40px) over large areas are the worst case; cap radius and panel size.
- 每个玻璃元素都会重新采样并模糊其后方的所有内容。限制元素数量;屏幕上出现十几个玻璃元素会严重降低滚动帧率。
- 将复杂的玻璃元素提升到独立图层(或
transform: translateZ(0)),动画结束后移除will-change: transform。will-change - 不要在元素上叠加其他
backdrop-filter元素——嵌套模糊会重复模糊已模糊的内容(二次性能开销)。backdrop-filter - 大半径(>40px)覆盖大面积是最坏情况;限制模糊半径和面板尺寸。
Accessibility — non-negotiable
无障碍适配——必不可少
Glass is decoration; content must stay legible and the effect must be defeatable.
css
@media (prefers-reduced-transparency: reduce) {
.glass { background: #1a1a2e; backdrop-filter: none; -webkit-backdrop-filter: none; }
.glass::after { display: none; } /* drop grain */
}
@media (prefers-reduced-motion: reduce) {
.glass { transition: none; }
.liquid { filter: none; } /* stop the refraction churn */
}
@supports not (backdrop-filter: blur(1px)) {
.glass { background: rgba(30,30,50,.85); } /* opaque-enough fallback */
}Contrast over busy backgrounds: translucent panels over photos can drop text below WCAG. Add a semi-opaque scrim or darkening gradient under the text, optionally , and verify ≥ 4.5:1 body / ≥ 3:1 large against the brightest region of the backdrop.
text-shadow: 0 1px 2px rgba(0,0,0,.4)玻璃效果只是装饰;内容必须保持可读性,且效果必须可关闭。
css
@media (prefers-reduced-transparency: reduce) {
.glass { background: #1a1a2e; backdrop-filter: none; -webkit-backdrop-filter: none; }
.glass::after { display: none; } /* drop grain */
}
@media (prefers-reduced-motion: reduce) {
.glass { transition: none; }
.liquid { filter: none; } /* stop the refraction churn */
}
@supports not (backdrop-filter: blur(1px)) {
.glass { background: rgba(30,30,50,.85); } /* opaque-enough fallback */
}繁杂背景上的对比度:图片背景上的半透明面板可能导致文本不符合WCAG标准。在文本下方添加半透明遮罩或加深渐变,可选择性添加,并验证文本与背景最亮区域的对比度:正文≥4.5:1,大文本≥3:1。
text-shadow: 0 1px 2px rgba(0,0,0,.4)Deliver & verify (standalone HTML)
交付与验证(独立HTML文件)
Packaged helper ():scripts/freezes thescripts/seek-shot.sh anim.html 0 1.5 3harness and screenshots each moment;?t=Ntiles them for one-glance review. Seescripts/contact-sheet.sh sheet.png frame-*.png.scripts/README.md
For a self-contained glass demo (card, nav, modal, liquid-glass hero) the deliverable is one HTML file that opens directly in a browser — markup, CSS, and (if liquid) one inline SVG filter, no build step. A single file is the right tier for a glass surface; don't reach for a bundler. The panel must overlap a real backdrop (drop in a photo or gradient) or there is nothing to frost and the demo lies.
Output contract:
- One file: a busy backdrop, your glass markup, the CSS (frost + edge highlight + grain + shadows), and any inline SVG
.htmlfilter.feDisplacementMap - A way to land on the resolved state and a frozen frame of any loop — glass verifies by both state (rest/hover/enter) and time (the sweep/refraction).
- Include the freeze harness below so any moment can be pinned for inspection.
Seek harness — pin a deterministic state + frame. forces the hover look; freezes CSS animations and the SVG refraction at seconds, so a screenshot lands on a still, deterministic frame:
?state=hover?t=NNhtml
<script>
const p = new URLSearchParams(location.search);
const state = p.get("state");
if (state) document.documentElement.dataset.state = state; // CSS keys off :root[data-state="hover"]
const t = p.get("t");
if (t !== null) {
document.getAnimations().forEach(a => { a.currentTime = parseFloat(t)*1000; a.pause(); }); // freeze CSS sweep
const svg = document.querySelector("svg");
svg?.pauseAnimations?.(); svg?.setCurrentTime?.(parseFloat(t)); // freeze refraction
}
window.__ready = true;
</script>Verify loop — render → set state/freeze → screenshot → check: open each meaningful state (, ) and a frozen loop frame (), screenshot, and confirm the glass reads as glass — blur and edge highlight visibly present, no color banding, text contrast holds over the backdrop — plus check artifacts (flat box because the backdrop is plain color, missing prefix in Safari, refraction too strong/molten, jank from animating blur). Then load and confirm the solid fallback renders legibly. Any headless tool works:
?state=rest?state=hover?t=2-webkit-prefers-reduced-transparencybash
npx playwright screenshot --wait-for-timeout=500 "file://$PWD/glass.html?state=hover" hover.png
npx playwright screenshot --wait-for-timeout=500 "file://$PWD/glass.html?t=2" loop.pngTo check the fallback headlessly, emulate the media feature (e.g. Playwright -style flags, or a query that toggles a class mirroring the media query) and screenshot that the panel is solid and readable.
--color-scheme?reduced=1Before you finish:
- Opens standalone — no console errors; the glass overlaps a real busy backdrop, not a flat color.
- Reads as glass — blur + bright edge highlight both visible, layered shadow floats it, no banding (grain present).
- Text contrast holds over the brightest part of the backdrop (≥ 4.5:1 body).
- /
?state=freeze lands a deterministic, settled frame.?t=N - → solid opaque panel;
prefers-reduced-transparency→ refraction/sweep stopped;prefers-reduced-motionfallback for no@supports.backdrop-filter - Performance sane — glass count limited, blur not animated on a janky path, liquid refraction on one element only.
打包工具(目录):scripts/可冻结scripts/seek-shot.sh anim.html 0 1.5 3测试工具并截取每个时刻的截图;?t=N可将截图拼接成一张预览图。详情见scripts/contact-sheet.sh sheet.png frame-*.png。scripts/README.md
对于独立的玻璃效果演示(卡片、导航栏、模态框、液态玻璃首屏),交付物应为可直接在浏览器中打开的单个HTML文件——包含标记、CSS,以及(如果使用液态效果)内嵌的SVG滤镜,无需构建步骤。单个文件是玻璃效果演示的最佳形式;无需使用打包工具。面板必须覆盖真实背景(插入图片或渐变),否则无法呈现磨砂效果,演示也就失去意义。
输出规范:
- 一个文件:包含繁杂背景、玻璃效果标记、CSS(磨砂+边缘高光+噪点+阴影),以及任何内嵌的SVG
.html滤镜。feDisplacementMap - 提供进入最终状态和冻结循环帧的方式——玻璃效果需通过状态(静止/悬停/进入)和时间(高光扫过/折射)两种方式验证。
- 包含以下冻结工具,以便固定任意时刻进行检查。
定位工具——固定确定性状态与帧。可强制呈现悬停效果;可冻结CSS动画和SVG折射效果在第秒的状态,以便截图获取静止的确定性帧:
?state=hover?t=NNhtml
<script>
const p = new URLSearchParams(location.search);
const state = p.get("state");
if (state) document.documentElement.dataset.state = state; // CSS keys off :root[data-state="hover"]
const t = p.get("t");
if (t !== null) {
document.getAnimations().forEach(a => { a.currentTime = parseFloat(t)*1000; a.pause(); }); // freeze CSS sweep
const svg = document.querySelector("svg");
svg?.pauseAnimations?.(); svg?.setCurrentTime?.(parseFloat(t)); // freeze refraction
}
window.__ready = true;
</script>验证循环——渲染→设置状态/冻结→截图→检查: 打开每个重要状态(、)和冻结的循环帧(),截图并确认玻璃效果呈现为玻璃质感——模糊和边缘高光均可见,分层阴影实现悬浮效果,无色彩带(噪点已添加),文本在背景上保持对比度——同时检查问题(因背景为纯色导致的扁平盒子效果、Safari中缺失前缀、折射效果过强/熔融状、模糊动画导致的卡顿)。然后开启模式,确认纯色回退方案可清晰呈现。任何无头工具均可完成此操作:
?state=rest?state=hover?t=2-webkit-prefers-reduced-transparencybash
npx playwright screenshot --wait-for-timeout=500 "file://$PWD/glass.html?state=hover" hover.png
npx playwright screenshot --wait-for-timeout=500 "file://$PWD/glass.html?t=2" loop.png要无头检查回退方案,可模拟媒体特性(例如Playwright的类标志,或通过查询参数切换模拟媒体查询的类),并截图确认面板为纯色且可读。
--color-scheme?reduced=1完成前检查:
- 可独立打开——无控制台错误;玻璃元素覆盖真实繁杂背景,而非纯色背景。
- 呈现玻璃质感——模糊和明亮边缘高光均可见,分层阴影实现悬浮效果,无色彩带(噪点已添加)。
- 文本与背景最亮区域的对比度达标(正文≥4.5:1)。
- /
?state=冻结可获取确定性的稳定帧。?t=N - 模式下显示纯色不透明面板;
prefers-reduced-transparency模式下停止折射/高光扫过动画;无prefers-reduced-motion支持时显示backdrop-filter回退方案。@supports - 性能合理——玻璃元素数量有限,模糊动画无卡顿,液态折射仅用于单个元素。
Quick reference
快速参考
| Need | Approach |
|---|---|
| Base frost | |
| Edge of glass | brighter |
| Float / depth | |
| Kill banding | |
| Hover motion | transition |
| Entrance | |
| Liquid refraction | |
| Specular sweep | skewed white gradient animated across surface |
| Safari | always pair |
| Reduced transparency | solid opaque panel, drop grain |
| No backdrop-filter | |
| 需求 | 实现方案 |
|---|---|
| 基础磨砂效果 | |
| 玻璃边缘 | 更亮的 |
| 悬浮/深度感 | |
| 消除色带 | |
| 悬停动效 | 为 |
| 入场动画 | |
| 液态折射效果 | |
| 镜面高光扫过 | 倾斜白色渐变在表面移动的动画 |
| Safari兼容 | 始终搭配 |
| 低透明度适配 | 纯色不透明面板,移除噪点 |
| 无backdrop-filter支持 | |
Reference files
参考文件
- — full copy-paste recipes: base glass card with tiers, the masked specular edge ring, anti-banding grain, hover/enter/scroll motion, the specular sweep, the SVG
references/glass-recipes.md/feDisplacementMapliquid-glass filter with tuning knobs, performance rules, the reduced-transparency/reduced-motion/feTurbulencefallbacks, contrast defenses, and the standalone freeze harness.@supports
- —— 完整的复制粘贴方案:不同层级的基础玻璃卡片、遮罩镜面边缘边框、抗色带噪点、悬停/入场/滚动动效、镜面高光扫过、SVG
references/glass-recipes.md/feDisplacementMap液态玻璃滤镜及调节参数、性能规则、低透明度/低动效/feTurbulence回退方案、对比度优化、独立冻结工具。@supports