Liquid glass tab bar app
A music app with a floating liquid glass tab bar: the glass bends the colour behind it, a lens slides and stretches between tabs, and the bar shrinks as you scroll.
"use client";
import {
useEffect,
useRef,
useState,
type CSSProperties,
type KeyboardEvent,
type PointerEvent,
type ReactNode,
} from "react";
import { Glass } from "./LiquidGlass";
import "./glass-tab-bar.css";
export type Tile = { title: string; by: string; hue: number };
export type Tab = {
id: string;
label: string;
icon: ReactNode;
heading: string;
tiles: Tile[];
};
/**
* GlassTabBar: a phone screen with a floating liquid glass tab bar.
* - The active tab sits under a glass lens that slides, stretches with speed and settles with a wobble.
* - Press and drag along the bar: the lens lifts, follows your finger and snaps to the nearest tab.
* - Scroll down and the bar shrinks to the current tab, scroll up and it grows back.
*/
export function GlassTabBar({ tabs }: { tabs: Tab[] }) {
const [active, setActive] = useState(0);
const [prev, setPrev] = useState(0);
const [min, setMin] = useState(false);
const [hop, setHop] = useState(0);
const bar = useRef<HTMLElement | null>(null);
const lens = useRef<HTMLElement | null>(null);
const scroller = useRef<HTMLDivElement>(null);
const drag = useRef<{
x0: number;
x: number;
t: number;
at: number;
on: boolean;
} | null>(null);
const lastY = useRef(0);
const n = tabs.length;
const tab = tabs[active];
const select = (i: number) => {
if (i === active) return;
setPrev(active);
setActive(i);
setHop((h) => h + 1);
scroller.current?.scrollTo({ top: 0 });
setMin(false);
};
// Lens position while dragging, in tab units (0 = first tab).
const place = (pos: number, stretch: number) => {
const el = lens.current;
if (!el) return;
el.style.setProperty("--pos", String(pos));
el.style.setProperty("--sx", String(1 + stretch));
el.style.setProperty("--sy", String(1 - stretch * 0.45));
};
const posAt = (clientX: number) => {
const b = bar.current!.getBoundingClientRect();
const k = (clientX - b.left - 6) / (b.width - 12);
return Math.max(0, Math.min(n - 1, k * n - 0.5));
};
const down = (e: PointerEvent<HTMLElement>) => {
if (min) return;
drag.current = {
x0: e.clientX,
x: e.clientX,
t: e.timeStamp,
at: posAt(e.clientX),
on: false,
};
bar.current!.dataset.held = "true";
};
const move = (e: PointerEvent<HTMLElement>) => {
const d = drag.current;
if (!d) return;
// A tap stays a tap: dragging only starts after 8px, then the bar keeps the pointer.
if (!d.on) {
if (Math.abs(e.clientX - d.x0) < 8) return;
d.on = true;
e.currentTarget.setPointerCapture(e.pointerId);
}
const now = e.timeStamp;
const v = Math.abs(e.clientX - d.x) / Math.max(1, now - d.t);
d.x = e.clientX;
d.t = now;
d.at = posAt(e.clientX);
bar.current!.dataset.dragging = "true";
place(d.at, Math.min(0.34, v * 0.18));
};
const up = () => {
const d = drag.current;
drag.current = null;
if (!bar.current) return;
bar.current.dataset.held = "false";
if (!d || bar.current.dataset.dragging !== "true") return;
bar.current.dataset.dragging = "false";
const to = Math.round(d.at);
place(to, 0);
lens.current?.style.removeProperty("--pos");
lens.current?.style.removeProperty("--sx");
lens.current?.style.removeProperty("--sy");
select(to);
};
const keys = (e: KeyboardEvent) => {
const k = { ArrowRight: 1, ArrowLeft: -1 }[e.key];
if (k) {
e.preventDefault();
const to = (active + k + n) % n;
select(to);
bar.current
?.querySelectorAll<HTMLButtonElement>("[role=tab]")
[to]?.focus();
} else if (e.key === "Home" || e.key === "End") {
e.preventDefault();
const to = e.key === "Home" ? 0 : n - 1;
select(to);
bar.current
?.querySelectorAll<HTMLButtonElement>("[role=tab]")
[to]?.focus();
}
};
useEffect(() => {
const el = scroller.current;
if (!el) return;
const onScroll = () => {
const y = el.scrollTop;
const dy = y - lastY.current;
lastY.current = y;
if (y < 40) setMin(false);
else if (dy > 6) setMin(true);
else if (dy < -6) setMin(false);
};
el.addEventListener("scroll", onScroll, { passive: true });
return () => el.removeEventListener("scroll", onScroll);
}, []);
const dir = active > prev ? 1 : -1;
const far = Math.abs(active - prev);
return (
<div className="gu-gtab">
<div className="gu-gtab__scroll" ref={scroller}>
<header className="gu-gtab__head" key={`h${active}`}>
<p>Good evening</p>
<h2>{tab.heading}</h2>
</header>
<div
className="gu-gtab__panel"
key={active}
data-dir={dir === 1 ? "right" : "left"}
role="tabpanel"
id={`gu-gtab-panel-${tab.id}`}
aria-labelledby={`gu-gtab-tab-${tab.id}`}
>
<div
className="gu-gtab__feature"
style={{ "--h": tab.tiles[0].hue } as CSSProperties}
>
<span className="gu-gtab__orb" aria-hidden="true" />
<span className="gu-gtab__orb" data-o="2" aria-hidden="true" />
<div>
<small>Made for you</small>
<strong>{tab.tiles[0].title}</strong>
<span>{tab.tiles[0].by}</span>
</div>
</div>
<ul className="gu-gtab__grid">
{tab.tiles.slice(1).map((t, i) => (
<li
key={t.title}
style={{ "--h": t.hue, "--i": i } as CSSProperties}
>
<span className="gu-gtab__art" aria-hidden="true">
<span />
</span>
<strong>{t.title}</strong>
<span>{t.by}</span>
</li>
))}
</ul>
</div>
</div>
<div className="gu-gtab__dock" data-min={min}>
<Glass
as="nav"
radius={999}
depth={34}
edge={16}
className="gu-gtab__bar"
glassRef={(node) => (bar.current = node)}
aria-label="Main"
onPointerDown={down}
onPointerMove={move}
onPointerUp={up}
onPointerCancel={up}
style={{ "--n": n, "--a": active } as CSSProperties}
>
<div
role="tablist"
aria-label="Sections"
onKeyDown={keys}
className="gu-gtab__tabs"
>
{tabs.map((t, i) => (
<button
key={t.id}
id={`gu-gtab-tab-${t.id}`}
type="button"
role="tab"
aria-selected={i === active}
aria-controls={`gu-gtab-panel-${t.id}`}
tabIndex={i === active ? 0 : -1}
onClick={() => select(i)}
data-active={i === active}
>
<span className="gu-gtab__icon" aria-hidden="true">
{t.icon}
</span>
<span className="gu-gtab__label">{t.label}</span>
</button>
))}
</div>
<Glass
radius={999}
depth={22}
edge={12}
tint={0.02}
tone="dark"
className="gu-gtab__lens"
glassRef={(node) => (lens.current = node)}
data-hop={hop === 0 ? undefined : hop % 2}
style={{ "--st": far > 1 ? 0.55 : 0.32 } as CSSProperties}
aria-hidden="true"
/>
</Glass>
<Glass
as="button"
type="button"
radius={999}
depth={26}
edge={14}
className="gu-gtab__search"
aria-label="Search"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="11" cy="11" r="6.5" />
<path d="m16 16 4.5 4.5" />
</svg>
</Glass>
</div>
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Liquid glass tab bar app
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A dark music app screen (390 × 844) with a floating "liquid glass" tab bar, in the style of the newest phone interfaces. The glass really bends the colourful content scrolling behind it (refraction at the rim), frosts it, and catches the light on its edge. The selected tab sits under a smaller glass lens that slides, stretches and wobbles like a drop of liquid.
## Layout and look
- Background #0b0b0f, white text, system sans-serif. Content scrolls under the bar with 120px of bottom padding.
- Header: small grey greeting (13px) and a big title (34px, weight 800, letter-spacing -0.03em) that changes per tab.
- A big feature card (230px tall, radius 26px) with a two-colour gradient made from a hue, plus two soft radial "orbs" that drift slowly, so there is always moving colour for the glass to bend.
- A 2-column grid of square tiles (radius 18px) drawn in code: a gradient cover with a small record in the middle, title and artist below.
- Bottom dock: 14px from the sides, sitting on the safe area. A pill-shaped glass bar (66px tall, 5px padding) with 4 tabs (icon 24px + 10.5px label), and a separate round glass search button (66px).
- Active tab colour: #ff8a5c.
## The glass
- Background rgba(255,255,255,0.1); backdrop-filter: blur(4px) saturate(1.9) brightness(1.06). Without refraction support use blur(14px).
- Refraction: an SVG filter with feImage (a displacement map generated for the element's exact size: neutral grey in the middle, a red gradient across x and a green gradient down y at the rim, the middle rounded rect blurred into the rim) and feDisplacementMap (scale about 30). Use it as `backdrop-filter: url(#lens) blur(...)` only in Chromium (check `navigator.userAgentData`); remeasure with a ResizeObserver using offsetWidth/offsetHeight.
- Rim light: a ::before ring 1.2px thick (mask-composite exclude) with a radial highlight at the pointer position (--lx, --ly, updated on pointermove) plus a fixed 135° highlight. A ::after sheen across the top.
- Shadows: inset top highlight, inset faint glow, and a soft drop shadow.
## Behavior and motion
1. Selecting a tab slides the lens there (translate, 620ms spring cubic-bezier(0.34,1.56,0.64,1)) while a keyframe stretches it along the way (scale 1.32 × 0.84 at 30%, or 1.55 × 0.78 when skipping a tab, then 0.94 × 1.06, then 1). Two identical keyframes alternate so it replays every time.
2. The active icon pops (scale 1.22 and up 2px) and the panel slides in 36px from the side you moved toward, the tiles following in a 50ms stagger with a blur-in.
3. Press the bar: it scales to 1.03 and the lens lifts (scale 1.12 × 1.18). Drag along it: the lens follows the finger, stretching with speed (1 + up to 0.34), and on release snaps to the nearest tab.
4. Scrolling down more than 6px shrinks the bar to only the current tab (76px wide); scrolling up or reaching the top brings it back, with a spring.
## Accessibility
- The tabs are a real tablist (role="tab", aria-selected, aria-controls, roving tabIndex). Left/Right arrows move and wrap, Home/End jump. Visible focus ring.
- The lens is aria-hidden. prefers-reduced-motion: no stretch, no slides, no drifting light. prefers-reduced-transparency: the glass becomes a solid surface.
## Props
tabs: { id, label, icon (an SVG), heading, tiles: { title, by, hue }[] }[]. The first tile of each tab is the feature card.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### GlassTabBar.tsx
```tsx
"use client";
import {
useEffect,
useRef,
useState,
type CSSProperties,
type KeyboardEvent,
type PointerEvent,
type ReactNode,
} from "react";
import { Glass } from "./LiquidGlass";
import "./glass-tab-bar.css";
export type Tile = { title: string; by: string; hue: number };
export type Tab = {
id: string;
label: string;
icon: ReactNode;
heading: string;
tiles: Tile[];
};
/**
* GlassTabBar: a phone screen with a floating liquid glass tab bar.
* - The active tab sits under a glass lens that slides, stretches with speed and settles with a wobble.
* - Press and drag along the bar: the lens lifts, follows your finger and snaps to the nearest tab.
* - Scroll down and the bar shrinks to the current tab, scroll up and it grows back.
*/
export function GlassTabBar({ tabs }: { tabs: Tab[] }) {
const [active, setActive] = useState(0);
const [prev, setPrev] = useState(0);
const [min, setMin] = useState(false);
const [hop, setHop] = useState(0);
const bar = useRef<HTMLElement | null>(null);
const lens = useRef<HTMLElement | null>(null);
const scroller = useRef<HTMLDivElement>(null);
const drag = useRef<{
x0: number;
x: number;
t: number;
at: number;
on: boolean;
} | null>(null);
const lastY = useRef(0);
const n = tabs.length;
const tab = tabs[active];
const select = (i: number) => {
if (i === active) return;
setPrev(active);
setActive(i);
setHop((h) => h + 1);
scroller.current?.scrollTo({ top: 0 });
setMin(false);
};
// Lens position while dragging, in tab units (0 = first tab).
const place = (pos: number, stretch: number) => {
const el = lens.current;
if (!el) return;
el.style.setProperty("--pos", String(pos));
el.style.setProperty("--sx", String(1 + stretch));
el.style.setProperty("--sy", String(1 - stretch * 0.45));
};
const posAt = (clientX: number) => {
const b = bar.current!.getBoundingClientRect();
const k = (clientX - b.left - 6) / (b.width - 12);
return Math.max(0, Math.min(n - 1, k * n - 0.5));
};
const down = (e: PointerEvent<HTMLElement>) => {
if (min) return;
drag.current = {
x0: e.clientX,
x: e.clientX,
t: e.timeStamp,
at: posAt(e.clientX),
on: false,
};
bar.current!.dataset.held = "true";
};
const move = (e: PointerEvent<HTMLElement>) => {
const d = drag.current;
if (!d) return;
// A tap stays a tap: dragging only starts after 8px, then the bar keeps the pointer.
if (!d.on) {
if (Math.abs(e.clientX - d.x0) < 8) return;
d.on = true;
e.currentTarget.setPointerCapture(e.pointerId);
}
const now = e.timeStamp;
const v = Math.abs(e.clientX - d.x) / Math.max(1, now - d.t);
d.x = e.clientX;
d.t = now;
d.at = posAt(e.clientX);
bar.current!.dataset.dragging = "true";
place(d.at, Math.min(0.34, v * 0.18));
};
const up = () => {
const d = drag.current;
drag.current = null;
if (!bar.current) return;
bar.current.dataset.held = "false";
if (!d || bar.current.dataset.dragging !== "true") return;
bar.current.dataset.dragging = "false";
const to = Math.round(d.at);
place(to, 0);
lens.current?.style.removeProperty("--pos");
lens.current?.style.removeProperty("--sx");
lens.current?.style.removeProperty("--sy");
select(to);
};
const keys = (e: KeyboardEvent) => {
const k = { ArrowRight: 1, ArrowLeft: -1 }[e.key];
if (k) {
e.preventDefault();
const to = (active + k + n) % n;
select(to);
bar.current
?.querySelectorAll<HTMLButtonElement>("[role=tab]")
[to]?.focus();
} else if (e.key === "Home" || e.key === "End") {
e.preventDefault();
const to = e.key === "Home" ? 0 : n - 1;
select(to);
bar.current
?.querySelectorAll<HTMLButtonElement>("[role=tab]")
[to]?.focus();
}
};
useEffect(() => {
const el = scroller.current;
if (!el) return;
const onScroll = () => {
const y = el.scrollTop;
const dy = y - lastY.current;
lastY.current = y;
if (y < 40) setMin(false);
else if (dy > 6) setMin(true);
else if (dy < -6) setMin(false);
};
el.addEventListener("scroll", onScroll, { passive: true });
return () => el.removeEventListener("scroll", onScroll);
}, []);
const dir = active > prev ? 1 : -1;
const far = Math.abs(active - prev);
return (
<div className="gu-gtab">
<div className="gu-gtab__scroll" ref={scroller}>
<header className="gu-gtab__head" key={`h${active}`}>
<p>Good evening</p>
<h2>{tab.heading}</h2>
</header>
<div
className="gu-gtab__panel"
key={active}
data-dir={dir === 1 ? "right" : "left"}
role="tabpanel"
id={`gu-gtab-panel-${tab.id}`}
aria-labelledby={`gu-gtab-tab-${tab.id}`}
>
<div
className="gu-gtab__feature"
style={{ "--h": tab.tiles[0].hue } as CSSProperties}
>
<span className="gu-gtab__orb" aria-hidden="true" />
<span className="gu-gtab__orb" data-o="2" aria-hidden="true" />
<div>
<small>Made for you</small>
<strong>{tab.tiles[0].title}</strong>
<span>{tab.tiles[0].by}</span>
</div>
</div>
<ul className="gu-gtab__grid">
{tab.tiles.slice(1).map((t, i) => (
<li
key={t.title}
style={{ "--h": t.hue, "--i": i } as CSSProperties}
>
<span className="gu-gtab__art" aria-hidden="true">
<span />
</span>
<strong>{t.title}</strong>
<span>{t.by}</span>
</li>
))}
</ul>
</div>
</div>
<div className="gu-gtab__dock" data-min={min}>
<Glass
as="nav"
radius={999}
depth={34}
edge={16}
className="gu-gtab__bar"
glassRef={(node) => (bar.current = node)}
aria-label="Main"
onPointerDown={down}
onPointerMove={move}
onPointerUp={up}
onPointerCancel={up}
style={{ "--n": n, "--a": active } as CSSProperties}
>
<div
role="tablist"
aria-label="Sections"
onKeyDown={keys}
className="gu-gtab__tabs"
>
{tabs.map((t, i) => (
<button
key={t.id}
id={`gu-gtab-tab-${t.id}`}
type="button"
role="tab"
aria-selected={i === active}
aria-controls={`gu-gtab-panel-${t.id}`}
tabIndex={i === active ? 0 : -1}
onClick={() => select(i)}
data-active={i === active}
>
<span className="gu-gtab__icon" aria-hidden="true">
{t.icon}
</span>
<span className="gu-gtab__label">{t.label}</span>
</button>
))}
</div>
<Glass
radius={999}
depth={22}
edge={12}
tint={0.02}
tone="dark"
className="gu-gtab__lens"
glassRef={(node) => (lens.current = node)}
data-hop={hop === 0 ? undefined : hop % 2}
style={{ "--st": far > 1 ? 0.55 : 0.32 } as CSSProperties}
aria-hidden="true"
/>
</Glass>
<Glass
as="button"
type="button"
radius={999}
depth={26}
edge={14}
className="gu-gtab__search"
aria-label="Search"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="11" cy="11" r="6.5" />
<path d="m16 16 4.5 4.5" />
</svg>
</Glass>
</div>
</div>
);
}
```
### glass-tab-bar.css
```css
.gu-gtab {
--spring: cubic-bezier(0.34, 1.56, 0.64, 1);
--ease: cubic-bezier(0.16, 1, 0.3, 1);
position: relative;
height: 100%;
overflow: hidden;
background: #0b0b0f;
color: #fff;
font-family:
ui-sans-serif,
system-ui,
-apple-system,
"Segoe UI",
sans-serif;
}
.gu-gtab__scroll {
height: 100%;
overflow-y: auto;
overscroll-behavior: contain;
padding: calc(var(--gu-safe-top, env(safe-area-inset-top, 0px)) + 14px) 18px
calc(var(--gu-safe-bottom, env(safe-area-inset-bottom, 0px)) + 120px);
scrollbar-width: none;
}
.gu-gtab__scroll::-webkit-scrollbar {
display: none;
}
.gu-gtab__head p {
margin: 0;
font-size: 13px;
color: rgb(255 255 255 / 0.55);
animation: gu-gtab-rise 0.6s var(--ease) backwards;
}
.gu-gtab__head h2 {
margin: 2px 0 18px;
font-size: 34px;
font-weight: 800;
letter-spacing: -0.03em;
animation: gu-gtab-rise 0.7s 0.05s var(--ease) backwards;
}
@keyframes gu-gtab-rise {
from {
opacity: 0;
translate: 0 12px;
filter: blur(6px);
}
}
.gu-gtab__panel[data-dir="right"] {
animation: gu-gtab-in-r 0.6s var(--ease) backwards;
}
.gu-gtab__panel[data-dir="left"] {
animation: gu-gtab-in-l 0.6s var(--ease) backwards;
}
@keyframes gu-gtab-in-r {
from {
opacity: 0;
translate: 36px 0;
}
}
@keyframes gu-gtab-in-l {
from {
opacity: 0;
translate: -36px 0;
}
}
/* Big feature card: moving coloured light, so the glass bar always has colour to bend. */
.gu-gtab__feature {
position: relative;
overflow: hidden;
display: flex;
align-items: flex-end;
height: 230px;
padding: 18px;
border-radius: 26px;
background: linear-gradient(
150deg,
hsl(var(--h) 90% 58%),
hsl(calc(var(--h) + 60) 85% 40%)
);
isolation: isolate;
}
.gu-gtab__orb {
position: absolute;
z-index: -1;
width: 70%;
aspect-ratio: 1;
border-radius: 50%;
top: -30%;
right: -20%;
background: radial-gradient(
circle,
hsl(calc(var(--h) - 40) 100% 70%),
transparent 65%
);
animation: gu-gtab-orb 9s ease-in-out infinite alternate;
}
.gu-gtab__orb[data-o="2"] {
left: -25%;
top: auto;
bottom: -40%;
background: radial-gradient(
circle,
hsl(calc(var(--h) + 140) 100% 62%),
transparent 65%
);
animation-duration: 12s;
}
@keyframes gu-gtab-orb {
to {
translate: -30% 25%;
scale: 1.3;
}
}
.gu-gtab__feature small {
display: block;
font-size: 12px;
font-weight: 600;
opacity: 0.8;
}
.gu-gtab__feature strong {
display: block;
margin: 2px 0;
font-size: 28px;
line-height: 1;
letter-spacing: -0.03em;
}
.gu-gtab__feature span {
font-size: 13px;
opacity: 0.85;
}
.gu-gtab__grid {
list-style: none;
margin: 18px 0 0;
padding: 0;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 18px 14px;
}
.gu-gtab__grid li {
animation: gu-gtab-rise 0.6s calc(0.12s + var(--i) * 0.05s) var(--ease)
backwards;
}
.gu-gtab__art {
display: grid;
place-items: center;
aspect-ratio: 1;
border-radius: 18px;
margin-bottom: 8px;
background:
radial-gradient(
circle at 30% 25%,
hsl(calc(var(--h) + 40) 100% 72%),
transparent 55%
),
linear-gradient(
160deg,
hsl(var(--h) 85% 55%),
hsl(calc(var(--h) + 80) 70% 28%)
);
}
.gu-gtab__art span {
width: 46%;
aspect-ratio: 1;
border-radius: 50%;
background: repeating-radial-gradient(
circle,
rgb(0 0 0 / 0.55) 0 2px,
rgb(0 0 0 / 0.35) 2px 4px
);
box-shadow: 0 0 0 6px rgb(255 255 255 / 0.12);
}
.gu-gtab__grid strong {
display: block;
font-size: 15px;
letter-spacing: -0.01em;
}
.gu-gtab__grid li > span:last-child {
font-size: 13px;
color: rgb(255 255 255 / 0.55);
}
/* ---------- The floating bar ---------- */
.gu-gtab__dock {
position: absolute;
left: 14px;
right: 14px;
bottom: calc(var(--gu-safe-bottom, env(safe-area-inset-bottom, 0px)) + 6px);
display: flex;
gap: 10px;
align-items: center;
z-index: 5;
}
.gu-gtab__bar {
--pad: 5px;
flex: 1;
height: 66px;
padding: var(--pad);
touch-action: none;
transition:
flex-basis 0.6s var(--spring),
max-width 0.6s var(--spring),
scale 0.4s var(--spring);
max-width: 100%;
}
.gu-gtab__bar[data-held="true"] {
scale: 1.03;
}
.gu-gtab__tabs {
position: relative;
z-index: 2;
display: grid;
grid-template-columns: repeat(var(--n), 1fr);
height: 100%;
}
.gu-gtab__tabs button {
all: unset;
box-sizing: border-box;
display: grid;
place-items: center;
align-content: center;
gap: 3px;
border-radius: 999px;
color: rgb(255 255 255 / 0.85);
cursor: pointer;
transition:
color 0.3s,
opacity 0.4s var(--ease),
scale 0.3s var(--spring);
-webkit-tap-highlight-color: transparent;
}
.gu-gtab__tabs button[data-active="true"] {
color: #ff8a5c;
}
.gu-gtab__tabs button:active {
scale: 0.9;
}
.gu-gtab__tabs button:focus-visible {
outline: 2px solid #fff;
outline-offset: -4px;
}
.gu-gtab__icon svg {
display: block;
width: 24px;
height: 24px;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.gu-gtab__tabs button[data-active="true"] .gu-gtab__icon {
animation: gu-gtab-pop 0.55s var(--spring);
}
@keyframes gu-gtab-pop {
40% {
scale: 1.22;
translate: 0 -2px;
}
}
.gu-gtab__label {
font-size: 10.5px;
font-weight: 600;
}
/* The lens: a smaller glass pill that slides between tabs. */
.gu-gtab__lens {
--pos: var(--a);
--sx: 1;
--sy: 1;
position: absolute;
z-index: 1;
top: var(--pad);
bottom: var(--pad);
left: var(--pad);
width: calc((100% - var(--pad) * 2) / var(--n));
translate: calc(var(--pos) * 100%) 0;
scale: var(--sx) var(--sy);
transition:
translate 0.62s var(--spring),
scale 0.5s var(--spring),
opacity 0.3s;
pointer-events: none;
}
/* While it travels it stretches along the way it moves, then settles with a small wobble.
Two identical keyframes take turns so the animation replays on every switch. */
.gu-gtab__lens[data-hop="0"] {
animation: gu-gtab-stretch-a 0.62s var(--ease);
}
.gu-gtab__lens[data-hop="1"] {
animation: gu-gtab-stretch-b 0.62s var(--ease);
}
@keyframes gu-gtab-stretch-a {
30% {
scale: calc(1 + var(--st)) calc(1 - var(--st) * 0.45);
}
62% {
scale: 0.94 1.06;
}
}
@keyframes gu-gtab-stretch-b {
30% {
scale: calc(1 + var(--st)) calc(1 - var(--st) * 0.45);
}
62% {
scale: 0.94 1.06;
}
}
.gu-gtab__bar[data-held="true"] .gu-gtab__lens {
scale: calc(var(--sx) * 1.12) calc(var(--sy) * 1.18);
transition:
translate 0.18s var(--ease),
scale 0.35s var(--spring);
}
.gu-gtab__bar[data-dragging="true"] .gu-gtab__lens {
animation: none;
}
.gu-gtab__search {
flex: none;
border: 0;
padding: 0;
font: inherit;
border-radius: 999px;
display: grid;
place-items: center;
width: 66px;
height: 66px;
cursor: pointer;
transition: scale 0.4s var(--spring);
}
.gu-gtab__search:active {
scale: 0.9;
}
.gu-gtab__search:focus-visible {
outline: 2px solid #fff;
outline-offset: 3px;
}
.gu-gtab__search svg {
width: 24px;
height: 24px;
fill: none;
stroke: #fff;
stroke-width: 2;
stroke-linecap: round;
}
/* Scrolled down: the bar shrinks to the current tab only. */
.gu-gtab__dock[data-min="true"] .gu-gtab__bar {
max-width: 76px;
}
.gu-gtab__dock[data-min="true"] .gu-gtab__tabs {
grid-template-columns: 1fr;
}
.gu-gtab__dock[data-min="true"]
.gu-gtab__tabs
button:not([data-active="true"]) {
display: none;
}
.gu-gtab__dock[data-min="true"] .gu-gtab__lens {
width: calc(100% - var(--pad) * 2);
translate: 0 0;
}
.gu-gtab__dock[data-min="true"] .gu-gtab__label {
display: none;
}
.gu-gtab__dock[data-min="true"] .gu-gtab__tabs button[data-active="true"] {
animation: gu-gtab-pop 0.5s var(--spring);
}
@media (prefers-reduced-motion: reduce) {
.gu-gtab *,
.gu-gtab *::before,
.gu-gtab *::after {
animation-duration: 0.01ms !important;
animation-delay: 0ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
```
### LiquidGlass.tsx
```tsx
"use client";
import {
useEffect,
useId,
useRef,
useState,
useSyncExternalStore,
type CSSProperties,
type ElementType,
type HTMLAttributes,
type PointerEvent,
type ReactNode,
} from "react";
import "./liquid-glass.css";
/*
* Liquid glass core. Copy this file and liquid-glass.css next to any glass piece.
* Real refraction (the background bending at the rim) uses an SVG filter inside backdrop-filter,
* which only Chromium browsers draw today. Everywhere else the glass keeps the same frost, rim light
* and shadows, so nothing ever looks broken.
*/
const never = () => () => {};
export function useCanRefract() {
return useSyncExternalStore(
never,
() =>
"userAgentData" in navigator &&
!window.matchMedia("(prefers-reduced-transparency: reduce)").matches,
() => false,
);
}
/**
* Displacement map for a rounded rectangle: neutral grey in the middle (no bending) and red/green
* ramps at the rim, so the background near the edge is pulled inward, like light through thick glass.
*/
function lensMap(w: number, h: number, r: number, edge: number) {
const e = Math.max(2, Math.min(edge, w / 2 - 1, h / 2 - 1));
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}"><defs><linearGradient id="x" x2="1"><stop offset="0" stop-color="#f00"/><stop offset="1" stop-color="#000"/></linearGradient><linearGradient id="y" x2="0" y2="1"><stop offset="0" stop-color="#0f0"/><stop offset="1" stop-color="#000"/></linearGradient><filter id="b" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="${(e / 2).toFixed(1)}"/></filter></defs><rect width="${w}" height="${h}" fill="#000"/><rect width="${w}" height="${h}" fill="url(#x)"/><rect width="${w}" height="${h}" fill="url(#y)" style="mix-blend-mode:screen"/><rect x="${e}" y="${e}" width="${w - 2 * e}" height="${h - 2 * e}" rx="${Math.max(0, r - e)}" fill="rgb(128,128,0)" filter="url(#b)"/></svg>`;
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
}
export type GlassProps = Omit<HTMLAttributes<HTMLElement>, "ref"> & {
as?: ElementType;
/** Corner radius in px (use a big number for a pill). */
radius?: number;
/** How far the rim bends the background, in px. */
depth?: number;
/** Width of the bending rim, in px. */
edge?: number;
/** Frost (blur) in px. */
blur?: number;
/** Milkiness of the glass, 0 to 1. */
tint?: number;
/** "light" is clear glass, "dark" is smoked glass. */
tone?: "light" | "dark";
/** Callback ref to the glass element. */
glassRef?: (node: HTMLElement | null) => void;
children?: ReactNode;
[data: `data-${string}`]: unknown;
type?: string;
disabled?: boolean;
};
/**
* Glass: one sheet of liquid glass.
* - Bends what is behind it at the rim (Chromium), frosts and saturates it everywhere.
* - The rim catches the light nearest the pointer, like a real edge turning toward a lamp.
*/
export function Glass({
as: Tag = "div",
radius = 24,
depth = 30,
edge = 14,
blur = 4,
tint = 0.1,
tone = "light",
className = "",
style,
children,
glassRef,
onPointerMove,
...rest
}: GlassProps) {
const id = `gu-lens-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
const el = useRef<HTMLElement | null>(null);
const [size, setSize] = useState<[number, number]>([0, 0]);
const refract = useCanRefract();
useEffect(() => {
const node = el.current;
if (!node || !refract) return;
const ro = new ResizeObserver(() => {
// offsetWidth ignores transforms, so a stretching lens keeps one stable map.
const w = node.offsetWidth;
const h = node.offsetHeight;
setSize((s) => (s[0] === w && s[1] === h ? s : [w, h]));
});
ro.observe(node);
return () => ro.disconnect();
}, [refract]);
const [w, h] = size;
const r = Math.min(radius, w / 2, h / 2);
const lens = refract && w > 4 && h > 4;
const frost = `blur(${blur}px) saturate(1.9) brightness(1.06)`;
const setRefs = (node: HTMLElement | null) => {
el.current = node;
glassRef?.(node);
};
const light = (e: PointerEvent<HTMLElement>) => {
const b = e.currentTarget.getBoundingClientRect();
e.currentTarget.style.setProperty(
"--lx",
`${((e.clientX - b.left) / b.width) * 100}%`,
);
e.currentTarget.style.setProperty(
"--ly",
`${((e.clientY - b.top) / b.height) * 100}%`,
);
onPointerMove?.(e);
};
return (
<Tag
ref={setRefs}
className={`gu-glass ${className}`}
data-tone={tone}
onPointerMove={light}
style={
{
"--r": `${radius}px`,
"--tint": tint,
...(lens
? {
backdropFilter: `url(#${id}) ${frost}`,
WebkitBackdropFilter: frost,
}
: null),
...style,
} as CSSProperties
}
{...rest}
>
{lens && (
<svg
className="gu-glass__defs"
width="0"
height="0"
aria-hidden="true"
focusable="false"
>
<filter
id={id}
x="0"
y="0"
width={w}
height={h}
filterUnits="userSpaceOnUse"
colorInterpolationFilters="sRGB"
>
<feImage
href={lensMap(w, h, r, edge)}
x="0"
y="0"
width={w}
height={h}
result="map"
preserveAspectRatio="none"
/>
<feDisplacementMap
in="SourceGraphic"
in2="map"
scale={depth}
xChannelSelector="R"
yChannelSelector="G"
/>
</filter>
</svg>
)}
{children}
</Tag>
);
}
/**
* GlassScene: a colourful, slowly moving backdrop drawn in code, so the glass has something to bend.
* Swap it for your own photo or page; the glass works over anything.
*/
export function GlassScene({
children,
className = "",
words = ["Liquid", "Glass", "Light", "Bend"],
style,
}: {
children?: ReactNode;
className?: string;
words?: string[];
style?: CSSProperties;
}) {
return (
<div className={`gu-scene ${className}`} style={style}>
<div className="gu-scene__bg" aria-hidden="true">
<span className="gu-scene__blob" data-b="1" />
<span className="gu-scene__blob" data-b="2" />
<span className="gu-scene__blob" data-b="3" />
<span className="gu-scene__blob" data-b="4" />
<div className="gu-scene__words">
{[0, 1, 2].map((row) => (
<div key={row} className="gu-scene__row" data-row={row}>
{[...words, ...words, ...words].map((w, i) => (
<span key={i}>{w}</span>
))}
</div>
))}
</div>
<span className="gu-scene__grid" />
</div>
<div className="gu-scene__fg">{children}</div>
</div>
);
}
```
### liquid-glass.css
```css
/* ---------- Liquid glass ---------- */
.gu-glass {
--r: 24px;
--tint: 0.1;
--lx: 30%;
--ly: 0%;
position: relative;
isolation: isolate;
border-radius: var(--r);
color: #fff;
background: rgb(255 255 255 / var(--tint));
-webkit-backdrop-filter: blur(14px) saturate(1.9) brightness(1.06);
backdrop-filter: blur(14px) saturate(1.9) brightness(1.06);
box-shadow:
inset 0 1px 0.5px rgb(255 255 255 / 0.6),
inset 0 -1px 1px rgb(255 255 255 / 0.14),
inset 0 0 18px rgb(255 255 255 / 0.08),
0 16px 36px -14px rgb(0 0 0 / 0.45),
0 3px 8px -3px rgb(0 0 0 / 0.22);
}
.gu-glass[data-tone="dark"] {
background: rgb(16 16 20 / calc(var(--tint) + 0.26));
box-shadow:
inset 0 1px 0.5px rgb(255 255 255 / 0.26),
inset 0 0 0 0.5px rgb(255 255 255 / 0.12),
0 16px 36px -14px rgb(0 0 0 / 0.55);
}
/* The rim: brightest where the pointer is, plus a fixed highlight top-left and a reflection bottom-right. */
.gu-glass::before {
content: "";
position: absolute;
inset: 0;
z-index: -1;
padding: 1.2px;
border-radius: inherit;
background:
radial-gradient(
160px 110px at var(--lx) var(--ly),
rgb(255 255 255 / 0.95),
transparent 70%
),
linear-gradient(
135deg,
rgb(255 255 255 / 0.7),
rgb(255 255 255 / 0.06) 35%,
rgb(255 255 255 / 0.02) 65%,
rgb(255 255 255 / 0.45)
);
-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);
transition: opacity 0.4s;
pointer-events: none;
}
/* A curved-surface sheen across the top. */
.gu-glass::after {
content: "";
position: absolute;
inset: 0;
z-index: -1;
border-radius: inherit;
background:
radial-gradient(
130% 80% at 50% -30%,
rgb(255 255 255 / 0.3),
transparent 58%
),
radial-gradient(
60% 40% at var(--lx) 120%,
rgb(255 255 255 / 0.12),
transparent 70%
);
pointer-events: none;
}
.gu-glass__defs {
position: absolute;
width: 0;
height: 0;
overflow: hidden;
pointer-events: none;
}
/* ---------- Scene (the colourful backdrop) ---------- */
.gu-scene {
position: relative;
isolation: isolate;
overflow: hidden;
border-radius: 28px;
background: #0e0e10;
color: #fff;
}
.gu-scene__bg {
position: absolute;
inset: 0;
z-index: 0;
overflow: hidden;
}
.gu-scene__blob {
position: absolute;
width: 60%;
aspect-ratio: 1;
border-radius: 50%;
filter: blur(36px);
opacity: 0.95;
animation: gu-scene-drift 18s ease-in-out infinite alternate;
}
.gu-scene__blob[data-b="1"] {
background: #ff5a1f;
left: -12%;
top: -18%;
}
.gu-scene__blob[data-b="2"] {
background: #2b35ff;
right: -16%;
top: 4%;
animation-duration: 22s;
animation-delay: -6s;
}
.gu-scene__blob[data-b="3"] {
background: #ff3d8b;
left: 18%;
bottom: -30%;
animation-duration: 26s;
animation-delay: -12s;
}
.gu-scene__blob[data-b="4"] {
background: #d7ff3a;
width: 26%;
right: 14%;
bottom: 6%;
animation-duration: 15s;
animation-delay: -3s;
opacity: 0.85;
}
@keyframes gu-scene-drift {
0% {
translate: 0 0;
scale: 1;
}
50% {
translate: 14% 10%;
scale: 1.18;
}
100% {
translate: -8% 16%;
scale: 0.92;
}
}
/* Big rows of type give the glass sharp edges to bend. */
.gu-scene__words {
position: absolute;
inset: -10% -20%;
display: grid;
align-content: center;
gap: 0.1em;
rotate: -8deg;
font:
800 clamp(48px, 9vw, 112px) / 0.95 ui-sans-serif,
system-ui,
sans-serif;
letter-spacing: -0.04em;
color: rgb(255 255 255 / 0.9);
mix-blend-mode: overlay;
}
.gu-scene__row {
display: flex;
gap: 0.45em;
white-space: nowrap;
animation: gu-scene-slide 40s linear infinite;
}
.gu-scene__row[data-row="1"] {
animation-direction: reverse;
animation-duration: 52s;
color: rgb(14 14 16 / 0.55);
}
.gu-scene__row[data-row="2"] {
animation-duration: 34s;
}
@keyframes gu-scene-slide {
to {
translate: -33.333% 0;
}
}
.gu-scene__grid {
position: absolute;
inset: 0;
background-image:
linear-gradient(rgb(255 255 255 / 0.12) 1px, transparent 1px),
linear-gradient(90deg, rgb(255 255 255 / 0.12) 1px, transparent 1px);
background-size: 28px 28px;
-webkit-mask: radial-gradient(80% 80% at 50% 50%, #000, transparent);
mask: radial-gradient(80% 80% at 50% 50%, #000, transparent);
}
.gu-scene__fg {
position: relative;
z-index: 1;
height: 100%;
}
@media (prefers-reduced-motion: reduce) {
.gu-scene__blob,
.gu-scene__row {
animation: none;
}
}
@media (prefers-reduced-transparency: reduce) {
.gu-glass {
background: rgb(244 244 248 / 0.94) !important;
color: #0e0e10;
-webkit-backdrop-filter: none !important;
backdrop-filter: none !important;
}
.gu-glass[data-tone="dark"] {
background: rgb(28 28 32 / 0.96) !important;
color: #fff;
}
}
```
You might also want
Next piece: Scroll-speed marqueeSplit bills app
Apps, intermediate
Music player
Apps, advanced
Smart home dial app
Apps, advanced