What does Liquid Glass Craft do?
A complete, from-scratch method for building real Liquid Glass. Not a CSS recipe collection, but a physical model + numerical implementation + tuning manual + pitfall log.
Reference implementation (index.html in the repo root, double-click to run): A dark music player interface with four glass panels — two capsules at the top, a playback bar at the bottom, and a queue overlay. Content scrolls under the glass, and the image inside the glass is recalculated every frame.
0. Read This First: Why Your Previous Attempt Wasn't Glass
Most "Liquid Glass" is actually frosted plastic. The one deciding criterion:
Real glass displaces what's behind it. Fake glass only blurs what's behind it.
- Blur is scattering: light directions are randomized, the image degrades into a low-frequency color patch field.
- Refraction is displacement: each pixel is moved elsewhere, the image structure is fully preserved, but geometry is altered.
- Frosted plastic = strong scattering + zero displacement. That's why it "looks like a film" rather than "like a material."
- Liquid Glass = weak scattering + strong edge displacement. The image barely moves in the center, and bends more sharply toward the edges.
So an executable acceptance test:
| Test | Frosted Plastic | Real Glass |
|---|---|---|
| Align a straight line (table line, text stroke, cover edge) inside the glass with the same line outside | Alignable, just blurry | Does not connect — it is broken and shifted upon entry |
| Set blur to 0 | Becomes sharp but completely flat | Still looks like glass because the bend remains |
| Move the mouse over the glass | No reaction, or a uniform white glow | A small patch of light follows the cursor, deformed when near the edge |
The second row is the most aggressive test. If your glass fails at blur: 0, you've actually implemented blur, and your refraction parameters are effectively zero.
1. Four-Layer Structure
A glass that can fool the eye is composed of four independent layers stacked together. Missing any one collapses the illusion.
┌─ ① Refraction Layer backdrop-filter: url(#svg-filter)
│ Displacement map = rounded rect SDF → edge profile → Snell → RGB encoding
│ Responsible for: displacing the background. This layer determines "is it glass?"
├─ ② Material Layer Thin white gradient fill (alpha 0.015–0.055)
│ Responsible for: glass being half a stop brighter than air. The difference between medium and air.
├─ ③ Reflection Layer Pointer highlight (canvas per-pixel) + optional fixed edge highlight
│ Responsible for: the surface is alive, has light. This layer determines "is it expensive?"
└─ ④ Depth Layer Outer drop shadow + edge darkening + inner fill gradient
Responsible for: the glass floats, has thickness. This layer determines "is it three-dimensional?"
Full breakdown of the four layers in docs/01-what-makes-it-glass.md.
2. Mandatory Workflow (Do Not Skip Steps)
Do it in order. Each step has a verifiable output. If you skip step 2, all subsequent parameters have no reference frame.
-
Prepare a background "worth refracting" (
docs/10-workflow.md§1) When glass sits on a solid color or uniform gradient, refraction is physically invisible. You need hard-edge structures: text, covers, grid lines, light-dark boundaries. → Acceptance: Screenshot the background and identify at least 5 high-frequency edges. -
First, do only displacement — no blur, no decoration (
docs/03-displacement-map.md)blur = 0, fill0, shadow0. At this point the glass should look "a bit dirty, a bit wobbly," but edges are clearly bending. → Acceptance: Withblur: 0, straight lines inside and outside the glass do not connect. Do not proceed if this step fails. -
Add material fill (
docs/05-transparency.md) Start from0.03and increase slowly until you "can tell there's something there." Above0.06it becomes a plastic plate. → Acceptance: The boundary between glass and background is visible, but you can still recognize the content behind it. -
Add blur (
docs/04-parameters.md—blursection) Start from 0.11 (5% of the max value of 2.2). This amount is so small it's almost unmeasurable; its function is to soften pixel-level hard edges, not to "blur." In most cases, this is enough — transparency is more important than "thickness." Max value is 2.2; above 0.2, you begin sacrificing transparency. → Acceptance: Text behind the glass is clearly readable but does not compete with foreground text for attention. -
Add depth (
docs/08-3d-depth.md) Drop shadow, edge darkening, fill gradient. No white lines. → Acceptance: The glass looks "closer" than the background by one stop. -
Finally, add highlights (
docs/07-specular-highlight.md) This layer is the easiest to mess up. It must be done last, or you will use highlights to hide defects from previous layers. → Acceptance: The light is a small patch, so subtle you "feel it but can't pinpoint it," and it deforms near the edges. -
Run the gates — all green means done (
docs/14-gates.md)node scripts/gate.mjs --url file:///your/index.html --sel ".glass"All nine must PASS to ship. If any FAIL, fix according to the chapter indicated by the error. Do not lower the thresholds. → Acceptance: The terminal's last line reads "All gates passed."
3. Acceptance Gates (Hard Thresholds)
Whether the glass is correct is not decided by your eyes at this moment, but by nine numbers.
This step is not a "suggested self-check" — it is the delivery standard. Because backdrop-filter can fail silently: a single leftover animation on an ancestor makes the whole pipeline sample an empty background, the page renders fine, the console is silent, and the screenshot looks decent. You will then waste three hours tuning parameters on a broken setup.
| Gate | What it checks | Threshold | Final version measurement |
|---|---|---|---|
| G1 | Refraction channel alive | Colored pixels ≥ 2% of area | 96.6% |
| G2 | Samples the real DOM layer (color probe) | Redness delta ≥ 6 | 165.7 |
| G3 | Only edges bend (read displacement field) | Edge ≥ 55/127, center ≤ 32/127 | 120 / 18 |
| G4 | No bright edge lines | Peak 0–4px must not exceed interior by 8 | 43.6 vs interior 50.6 |
| G5 | Transparent, not a whiteboard | Center brightness Δ ≤ 14, interior std ≥ 12 | 8.2 / 63.2 |
| G6 | Glare capped | Peak alpha 5–52, zero saturated pixels, zero hard edges | 15 / 0 / 0 |
| G7 | Glare does not overflow | Bright pixels outside boundary (8px) ≤ 6 | 0 |
| G8 | Text readable | Large text 3.0:1, rest 2.8:1 | 3.08 |
| G9 | 3D depth (outer drop shadow) | Far region brighter than immediately below ≥ 1.5 | 2.6 |
Three Non-Negotiable Rules
- All nine must PASS to ship. One FAIL means it's not done. There is no "close enough because the rest passed."
- Do not lower thresholds to pass. Thresholds are reverse-engineered from real user feedback (glare alone went through five rounds of rework;
gneardropped from 1.72 to 0.18). Changing them changes the requirements. - SKIP is not PASS. G6 SKIPs if no
.glare canvasis found — that means the check isn't covering that element. It must be manually verified, and the reason documented in the delivery notes.
Do the Gates Actually Catch Errors?
After passing on the final version, we intentionally created three broken copies to verify:
| Fault | Injection | Result |
|---|---|---|
| Whiteboard | White fill raised to 0.26 | G5 FAIL, brightness Δ = 43.3 |
| White edge | inset 0 1px 0 rgba(255,255,255,.85) | G4 FAIL, peak = 232.4 |
| Broken pipeline | backdrop-filter: blur(9px) overriding url() | G3 FAIL, reports "no url(#...) reference" |
All three were caught, and the error pointed directly to the root cause. A gate that hasn't been negatively validated is as good as unwritten — you must do this step when adding your own gates.
For each gate's motivation, principle, threshold origin, FAIL remedy, and the gate's own limitations, see docs/14-gates.md.
4. Three Untouchable Red Lines
Violating any one will cause the glass to fail completely, with no error reported. All three are fundamentally in the causes of G1 failure.
-
No ancestor of the glass element may have
transform/filter/opacity < 1, including animation residues. If any does, Blink treats it as a backdrop root, andbackdrop-filtersamples an empty background. Even an entrance animation that settles atopacity: 1still sets the root — once an animation is declared, it remains a backdrop root. Seedocs/09-pitfalls.md§1. This is the most expensive pitfall; I wasted two hours on it. -
backdrop-filtercan only have a single filter function.url(#x) blur(4px)will be discarded entirely. All blur/saturate/color adjustments must be moved inside the SVG filter. -
The SVG
filterregion for the highlight layer must be locked to0/0/100%/100%. An element'soverflow: hiddendoes not constrain filter output. If the region expands, displacement pushes the light outside the glass.
5. Parameter Quick Reference
All parameters are passed via <html data-*>, with defaults on the JS side.
| Attribute | Default | Effect | Common Range | Consequence of Increasing |
|---|---|---|---|---|
data-edge | 52 | Maximum edge refraction strength (CSS px) | 40–80 | Edge looks cracked, like a spherical lens |
data-mag | 8 | Overall magnification parallax (CSS px) | 6–13 | Glass becomes a convex lens, content shrinks and expands outward |
data-thick | 0.32 | Refraction band width = half short side × factor | 0.28–0.42 | Bend zone expands, center begins to bend |
data-thickmax | 22 | Max refraction band width (px) | 18–30 | Edge bend on large elements too thick, looks like a droplet |
data-blur | 0.11 | Glass haze (max 2.2, i.e., 5%) | 0–0.15 | Becomes frosted, transparency disappears |
data-sat | 1.32 | Saturation of content seen through glass | 1.2–1.7 | Colors too vivid, looks like a filter |
data-lift | 1.04 | Contrast slope | 0.80–0.90 (to recede) / 1.0 (neutral) | Background becomes more prominent, fights foreground |
data-lift0 | 0.008 | Contrast intercept (raises black) | 0.03–0.06 | Overall grayish |
data-spec | 1 | Fixed edge specular highlight | 0 or 1 | Uniform white edge appears (source of cheap look) |
data-gnear | 0.18 | Cursor glare intensity | 0.18–0.25 | Above 0.5 becomes a blob of white |
data-gfar | 0 | Backside secondary image intensity | 0 (default off) | A second patch of light appears on the opposite side |
data-glag | 0.20 | Following lag | 0.12–0.30 | Light cannot keep up with cursor |
The only one sentence you need to remember from this table: data-edge decides "how glassy it is," data-gnear decides "how cheap it looks." These are the main knobs; everything else is supporting.
For each parameter's physical meaning, magnitude derivation, and failure symptoms, see docs/04-parameters.md.
6. Table of Contents
Core
docs/01-what-makes-it-glass.md— The essence of glass. Four physical quantities, visual criteria, why blur is not refraction.docs/02-backdrop-pipeline.md— Web implementation pipeline. Capabilities and limits ofbackdrop-filter, full filter chain derivation.docs/03-displacement-map.md— Displacement map generation. SDF, Snell derivation, numerical details, range, encoding. The longest chapter.docs/04-parameters.md— Full parameter guide. Physical meaning and failure symptoms of each knob.
Material
docs/05-transparency.md— How transparent? Fill gradient, contrast compression, pitfalls in light mode.docs/06-edge-refraction.md— Edge special topic. Why white edges are inevitably cheap, and what communicates boundaries.docs/07-specular-highlight.md— Glare (not a glow halo). Per-pixel algorithm, size, presence grading, secondary images.docs/08-3d-depth.md— 3D depth. Five contributors, shadow grading, light source consistency.
Engineering
docs/09-pitfalls.md— All pitfalls, sorted by cost. The first is the most expensive (cost two hours).docs/10-workflow.md— Full from-scratch workflow, including acceptance criteria for each step.docs/11-verification.md— How to verify. Pixel difference method, headless screenshot, self-check checklist.docs/12-apple-principles.md— Apple's design principles for glass. Glass only for control layers, no stacked glass.docs/14-gates.md— Nine acceptance gates. Each gate's motivation, threshold origin, FAIL remedy, and the gate's own limitations.
Recipes
docs/13-recipes.md— Scene presets. Toolbar / floating bar / sidebar / modal / round button, each with full parameter set + CSS. See this first when unsure what values to use.
Tools
scripts/gate.mjs— Gate script. Launches headless browser, takes screenshot, assesses each item, outputs report. Exit code 0 = all passed.scripts/README.md— Script usage and parameters.
Examples
index.html+styles.css+glass.js— Complete runnable reference implementation, open and use (dark mode).EXAMPLE.md— File structure, key code locations, how to adapt for your own use.
7. Quick Start (Copy-Paste Route)
Don't write from scratch. Copy the four files in the root (index.html / styles.css / glass.js / app.js), then modify in this order:
styles.css— the.glassblock. Define your shape and material. Changeborder-radiusto decide capsule vs. card.index.html— thedata-*attributes. Adjustedgeandmagper §5.glass.js— No changes needed. It's pure geometric computation, unrelated to your design.app.js— only contains press, playback, progress interactions. Delete if not needed.- If supporting light mode, read the last section of
docs/05-transparency.md. Do not simply invert the background. - Run the gates — all green before shipping:
node scripts/gate.mjs --url file:///your/index.html --sel ".glass".
8. One-Sentence Summary
Glass is not a visual effect; it is a displacement field. What you tune is not "transparency" — it is "how many pixels, and where, the background is bent."