Skip to content

Glass Toolbar

Liquid Glass toolbar for React: grouped controls with a sliding selection lens, labelled icons and a soft scroll-edge blur.

  • Liquid Glass
  • Developer tools
  • React only · 0 deps
  • 2 files
Full screen

Browser support · Real refraction (SVG displacement inside backdrop-filter) in Chromium browsers. Safari and Firefox fall back to a frosted blur with the same rim and highlights.

Install. One command, or copy the file.

$npx shadcn@latest add https://freedesignmd.com/r/glass-toolbar.json
  • Byte-identical to the preview
  • No Tailwind or config needed
  • SSR-safe · keyboard accessible
  • Respects reduced motion & transparency
components/liquid-glass/glass-toolbar.tsx
1/**
2 * GlassToolbar, grouped Liquid Glass toolbar with a scroll edge effect.
3 *
4 * HIG rules baked in:
5 * - Related actions share one glass capsule (a group); groups are separated by
6 * fixed spacers, never stacked glass on glass.
7 * - Icon groups and text groups are separate (don't mix in one capsule).
8 * - Every icon has an accessibility label (also shown as a tooltip).
9 * - The selected tool sits under a soft lens that slides between items.
10 * - <ScrollEdge> softly blurs + fades content scrolling under a bar.
11 *
12 * Components:
13 * <GlassToolbar label tone tooltips>, role="toolbar"; Arrow keys move between all
14 * items across groups (roving tabindex).
15 * <ToolbarGroup selectable value onChange>, one glass capsule.
16 * <ToolbarItem id label icon? text? onClick?>, icon-only items need `label`.
17 * <ToolbarSpacer flexible?>, fixed gap (default) or flexible.
18 * <ScrollEdge edge="top"|"bottom" size tone>, place inside a scroll
19 * container's positioned parent, above content and below the bar.
20 * Browser support: refraction in Chromium; frosted glass elsewhere.
21 */
22import { Children, createContext, isValidElement, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
23import type { CSSProperties, KeyboardEvent, ReactNode } from "react";
24import { GlassScope, LiquidGlass, useGlassEnv, useSpring } from "./liquid-glass";
25
26type Tone = "light" | "dark";
27const ToneCtx = createContext<Tone>("light");
28type GroupCtx = { selectable: boolean; value?: string; onChange?: (id: string) => void };
29const GroupContext = createContext<GroupCtx>({ selectable: false });
30
31const useIso = typeof window === "undefined" ? useEffect : useLayoutEffect;
32
33export function GlassToolbar({
34 label,
35 tone = "light",
36 tooltips = "below",
37 children,
38 className,
39 style,
40}: {
41 label: string;
42 tone?: Tone;
43 /** Where icon tooltips appear: "below" for top bars, "above" for bottom bars. */
44 tooltips?: "above" | "below";
45 children: ReactNode;
46 className?: string;
47 style?: CSSProperties;
48}) {
49 const ref = useRef<HTMLDivElement | null>(null);
50 // roving tabindex across every item in every group
51 useEffect(() => {
52 const el = ref.current;
53 if (!el) return;
54 const items = Array.from(el.querySelectorAll<HTMLElement>(".fd-gtb-item:not(:disabled)"));
55 const current = items.find((i) => i.getAttribute("aria-pressed") === "true" || i.getAttribute("aria-checked") === "true") ?? items[0];
56 items.forEach((i) => (i.tabIndex = i === current ? 0 : -1));
57 });
58 const onKey = (e: KeyboardEvent<HTMLDivElement>) => {
59 const items = Array.from(ref.current?.querySelectorAll<HTMLElement>(".fd-gtb-item:not(:disabled)") ?? []);
60 const i = items.indexOf(document.activeElement as HTMLElement);
61 if (i < 0) return;
62 const map: Record<string, number> = { ArrowRight: i + 1, ArrowLeft: i - 1, Home: 0, End: items.length - 1 };
63 if (!(e.key in map)) return;
64 e.preventDefault();
65 const n = items[(map[e.key] + items.length) % items.length];
66 items.forEach((x) => (x.tabIndex = -1));
67 n.tabIndex = 0;
68 n.focus();
69 };
70 return (
71 <ToneCtx.Provider value={tone}>
72 <GlassScope>
73 <div ref={ref} role="toolbar" aria-label={label} className={["fd-gtb", `fd-gtb--${tone}`, `fd-gtb--tips-${tooltips}`, className ?? ""].filter(Boolean).join(" ")} style={style} onKeyDown={onKey}>
74 <style>{css}</style>
75 {children}
76 </div>
77 </GlassScope>
78 </ToneCtx.Provider>
79 );
80}
81
82export function ToolbarGroup({
83 children,
84 selectable = false,
85 value,
86 onChange,
87 label,
88}: {
89 children: ReactNode;
90 selectable?: boolean;
91 value?: string;
92 onChange?: (id: string) => void;
93 label?: string;
94}) {
95 const tone = useContext(ToneCtx);
96 const env = useGlassEnv();
97 const inner = useRef<HTMLDivElement | null>(null);
98 const lens = useRef<HTMLSpanElement | null>(null);
99 const text = Children.toArray(children).some((c) => isValidElement(c) && (c.props as { text?: string }).text && !(c.props as { icon?: ReactNode }).icon);
100
101 const paint = () => {
102 const l = lens.current;
103 if (!l) return;
104 const st = env.reducedMotion ? 0 : Math.min(0.3, Math.abs(lx.velocity) * 0.0005);
105 l.style.transform = `translateX(${lx.value.toFixed(2)}px) scale(${(1 + st).toFixed(4)}, ${(1 - st * 0.4).toFixed(4)})`;
106 l.style.width = `${lw.value.toFixed(2)}px`;
107 };
108 const lx = useSpring(0, paint, { stiffness: 380, damping: 28 });
109 const lw = useSpring(0, paint, { stiffness: 380, damping: 30 });
110 const first = useRef(true);
111 useIso(() => {
112 if (!selectable) return;
113 const el = inner.current?.querySelector<HTMLElement>(`[data-id="${CSS.escape(value ?? "")}"]`);
114 if (!el || !lens.current) {
115 if (lens.current) lens.current.style.opacity = "0";
116 return;
117 }
118 lens.current.style.opacity = "1";
119 if (first.current || env.reducedMotion) {
120 lx.set(el.offsetLeft);
121 lw.set(el.offsetWidth);
122 first.current = false;
123 } else {
124 lx.to(el.offsetLeft);
125 lw.to(el.offsetWidth);
126 }
127 }, [value, selectable, env.reducedMotion]);
128
129 return (
130 <GroupContext.Provider value={{ selectable, value, onChange }}>
131 <LiquidGlass className={`fd-gtb-group${text ? " is-text" : ""}`} variant="regular" tone={tone} radius="capsule" role="group" aria-label={label}>
132 <div ref={inner} className="fd-gtb-inner">
133 {selectable && <span ref={lens} className="fd-gtb-lens" aria-hidden="true" />}
134 {children}
135 </div>
136 </LiquidGlass>
137 </GroupContext.Provider>
138 );
139}
140
141export function ToolbarItem({
142 id,
143 label,
144 icon,
145 text,
146 onClick,
147 disabled,
148 pressed,
149 shortcut,
150}: {
151 id: string;
152 /** Accessible name + tooltip. Required for icon-only items. */
153 label: string;
154 icon?: ReactNode;
155 /** Text label (use text-only groups). */
156 text?: string;
157 onClick?: () => void;
158 disabled?: boolean;
159 /** Toggle state for non-selectable toggle items. */
160 pressed?: boolean;
161 shortcut?: string;
162}) {
163 const g = useContext(GroupContext);
164 const selected = g.selectable ? g.value === id : pressed;
165 return (
166 <button
167 type="button"
168 className={`fd-gtb-item${text && !icon ? " is-text" : ""}`}
169 data-id={id}
170 aria-label={icon ? label : undefined}
171 aria-pressed={selected === undefined ? undefined : selected}
172 disabled={disabled}
173 onClick={() => {
174 if (g.selectable) g.onChange?.(id);
175 onClick?.();
176 }}
177 >
178 {icon ? <span className="fd-gtb-ico" aria-hidden="true">{icon}</span> : null}
179 {text && !icon ? <span className="fd-gtb-txt">{text}</span> : null}
180 {icon ? (
181 <span className="fd-gtb-tip" role="presentation" aria-hidden="true">
182 {label}
183 {shortcut ? <kbd>{shortcut}</kbd> : null}
184 </span>
185 ) : null}
186 </button>
187 );
188}
189
190export function ToolbarSpacer({ flexible = false }: { flexible?: boolean }) {
191 return <span className={`fd-gtb-spacer${flexible ? " is-flex" : ""}`} aria-hidden="true" />;
192}
193
194/** Scroll edge effect: a progressive blur + fade where content passes under a bar. */
195export function ScrollEdge({ edge = "top", size = 96, tone = "light", style }: { edge?: "top" | "bottom"; size?: number; tone?: Tone; style?: CSSProperties }) {
196 return (
197 <div className={`fd-gtb-edge fd-gtb-edge--${edge} fd-gtb-edge--${tone}`} style={{ height: size, ...style }} aria-hidden="true">
198 <style>{css}</style>
199 <span style={{ "--b": "1px", "--a": "0%", "--z": "45%" } as CSSProperties} />
200 <span style={{ "--b": "3px", "--a": "0%", "--z": "70%" } as CSSProperties} />
201 <span style={{ "--b": "8px", "--a": "0%", "--z": "100%" } as CSSProperties} />
202 </div>
203 );
204}
205
206const css = `
207.fd-gtb,.fd-gtb *,.fd-gtb *::before,.fd-gtb *::after{box-sizing:border-box}
208.fd-gtb{display:flex;align-items:center;gap:0;margin:0;padding:0;background:none;border:0;color:#0B0B0F;font:500 14px/1 ui-sans-serif,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",Roboto,sans-serif;letter-spacing:normal}
209.fd-gtb--dark{color:#F2F2F7}
210.fd-gtb-group{flex:none;height:48px;padding:4px}
211.fd-gtb-inner{position:relative;display:flex;align-items:center;gap:2px;height:100%;margin:0;padding:0}
212.fd-gtb-lens{position:absolute;left:0;top:0;bottom:0;width:0;margin:0;padding:0;border-radius:999px;pointer-events:none;will-change:transform,width;
213 background:rgba(11,11,15,0.08);box-shadow:inset 0 0 0 0.5px rgba(255,255,255,0.5)}
214.fd-gtb--dark .fd-gtb-lens{background:rgba(255,255,255,0.16)}
215.fd-gtb-spacer{display:block;flex:none;width:12px;height:1px;margin:0;padding:0}
216.fd-gtb-spacer.is-flex{flex:1 1 12px}
217.fd-gtb-item{position:relative;display:inline-flex;align-items:center;justify-content:center;flex:none;width:40px;height:40px;margin:0;padding:0;border:0;border-radius:999px;background:transparent;color:inherit;
218 font:600 14px/1 ui-sans-serif,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",Roboto,sans-serif;letter-spacing:-0.005em;text-shadow:none;cursor:pointer;-webkit-appearance:none;appearance:none;-webkit-tap-highlight-color:transparent;
219 transition:background-color var(--fd-dur-1) linear,transform var(--fd-dur-3) var(--fd-spring),color var(--fd-dur-2) var(--fd-ease-out)}
220.fd-gtb-item.is-text{width:auto;padding:0 14px}
221.fd-gtb-item:hover:not(:disabled){background:rgba(11,11,15,0.05)}
222.fd-gtb--dark .fd-gtb-item:hover:not(:disabled){background:rgba(255,255,255,0.08)}
223.fd-gtb-item:active:not(:disabled){transform:scale(0.9);transition-duration:var(--fd-dur-1)}
224.fd-gtb-item[aria-pressed="true"]{color:#007AFF}
225.fd-gtb--dark .fd-gtb-item[aria-pressed="true"]{color:#0A84FF}
226.fd-gtb-item:disabled{opacity:0.35;cursor:default}
227.fd-gtb-item:focus-visible{outline:2px solid color-mix(in srgb,#0A84FF 70%,transparent);outline-offset:2px}
228.fd-gtb-ico,.fd-gtb-ico svg{display:block;width:22px;height:22px;margin:0;padding:0}
229.fd-gtb-txt{display:block;margin:0;padding:0;white-space:nowrap}
230.fd-gtb-tip{position:absolute;left:50%;top:calc(100% + 12px);display:flex;align-items:center;gap:8px;margin:0;padding:7px 10px;border-radius:10px;background:rgba(28,28,34,0.94);color:#F2F2F7;
231 font:600 12px/1 ui-sans-serif,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",Roboto,sans-serif;letter-spacing:0;white-space:nowrap;pointer-events:none;opacity:0;transform:translate(-50%,-4px) scale(0.96);
232 transition:opacity var(--fd-dur-1) linear,transform var(--fd-dur-2) var(--fd-ease-out);z-index:10;box-shadow:0 8px 20px -6px rgba(0,0,0,0.35)}
233.fd-gtb--tips-above .fd-gtb-tip{top:auto;bottom:calc(100% + 12px);transform:translate(-50%,4px) scale(0.96)}
234.fd-gtb-tip kbd{display:inline-block;margin:0;padding:3px 5px;border:0;border-radius:5px;background:rgba(255,255,255,0.14);color:#C7C7CC;font:500 11px/1 ui-monospace,"SF Mono","JetBrains Mono",Menlo,monospace}
235.fd-gtb-item:hover .fd-gtb-tip,.fd-gtb-item:focus-visible .fd-gtb-tip{opacity:1;transform:translate(-50%,0) scale(1);transition-delay:350ms,350ms}
236.fd-gtb-item:focus-visible .fd-gtb-tip{transition-delay:0ms,0ms}
237.fd-gtb-edge{position:absolute;left:0;right:0;z-index:2;margin:0;padding:0;pointer-events:none;display:block}
238.fd-gtb-edge--top{top:0}
239.fd-gtb-edge--bottom{bottom:0}
240.fd-gtb-edge span{position:absolute;inset:0;display:block;margin:0;padding:0;-webkit-backdrop-filter:blur(var(--b));backdrop-filter:blur(var(--b))}
241.fd-gtb-edge--top span{-webkit-mask:linear-gradient(180deg,#000 var(--a),transparent var(--z));mask:linear-gradient(180deg,#000 var(--a),transparent var(--z))}
242.fd-gtb-edge--bottom span{-webkit-mask:linear-gradient(0deg,#000 var(--a),transparent var(--z));mask:linear-gradient(0deg,#000 var(--a),transparent var(--z))}
243.fd-gtb-edge--top.fd-gtb-edge--light{background:linear-gradient(180deg,rgba(247,247,249,0.85),rgba(247,247,249,0))}
244.fd-gtb-edge--bottom.fd-gtb-edge--light{background:linear-gradient(0deg,rgba(247,247,249,0.85),rgba(247,247,249,0))}
245.fd-gtb-edge--top.fd-gtb-edge--dark{background:linear-gradient(180deg,rgba(11,11,15,0.85),rgba(11,11,15,0))}
246.fd-gtb-edge--bottom.fd-gtb-edge--dark{background:linear-gradient(0deg,rgba(11,11,15,0.85),rgba(11,11,15,0))}
247@media (prefers-reduced-transparency: reduce){.fd-gtb-edge span{-webkit-backdrop-filter:none;backdrop-filter:none}}
248@media (prefers-reduced-motion: reduce){.fd-gtb-item:active:not(:disabled){transform:none}.fd-gtb-tip{transition-duration:0ms}}
249`;
250
251/* ───────────────────────── demo ───────────────────────── */
252
253const s = (d: ReactNode) => (
254 <svg aria-hidden="true" focusable="false" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
255 {d}
256 </svg>
257);
258const IC = {
259 select: s(<path d="m5.5 4 13 6.2-5.6 1.8-1.8 5.6Z" />),
260 frame: s(<path d="M8 3.5v17M16 3.5v17M3.5 8h17M3.5 16h17" />),
261 pen: s(<><path d="M12 19.5 19.5 12l-3-3L9 16.5Z" /><path d="m16.5 9-2-6-11 3.5L7 17.5l2-1M4 6.5l5 5" /></>),
262 text: s(<path d="M5.5 6V4.5h13V6M12 4.5v15M9 19.5h6" />),
263 comment: s(<path d="M5 18.5V7a2.5 2.5 0 0 1 2.5-2.5h9A2.5 2.5 0 0 1 19 7v6.5a2.5 2.5 0 0 1-2.5 2.5H9Z" />),
264 bold: s(<path d="M7 4.5h6a3.5 3.5 0 0 1 0 7H7Zm0 7h7a4 4 0 0 1 0 8H7Z" />),
265 italic: s(<path d="M10 4.5h8M6 19.5h8M14 4.5l-4 15" />),
266 link: s(<path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1" />),
267};
268
269export function Demo() {
270 const [tool, setTool] = useState("select");
271 const [bold, setBold] = useState(false);
272 const [italic, setItalic] = useState(true);
273 return (
274 <div className="fd-gtbd">
275 <style>{demoCss}</style>
276 <div className="fd-gtbd-stage">
277 <GlassToolbar label="Tools">
278 <ToolbarGroup label="Tools" selectable value={tool} onChange={setTool}>
279 <ToolbarItem id="select" label="Move" icon={IC.select} shortcut="V" />
280 <ToolbarItem id="frame" label="Frame" icon={IC.frame} shortcut="F" />
281 <ToolbarItem id="pen" label="Pen" icon={IC.pen} shortcut="P" />
282 <ToolbarItem id="text" label="Text" icon={IC.text} shortcut="T" />
283 <ToolbarItem id="comment" label="Comment" icon={IC.comment} shortcut="C" />
284 </ToolbarGroup>
285 <ToolbarSpacer />
286 <ToolbarGroup label="Format">
287 <ToolbarItem id="bold" label="Bold" icon={IC.bold} pressed={bold} onClick={() => setBold((b) => !b)} shortcut="⌘ B" />
288 <ToolbarItem id="italic" label="Italic" icon={IC.italic} pressed={italic} onClick={() => setItalic((b) => !b)} shortcut="⌘ I" />
289 <ToolbarItem id="link" label="Link" icon={IC.link} shortcut="⌘ K" />
290 </ToolbarGroup>
291 </GlassToolbar>
292 </div>
293 </div>
294 );
295}
296
297const F = `ui-sans-serif,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",Roboto,sans-serif`;
298
299const demoCss = `
300.fd-gtbd,.fd-gtbd *,.fd-gtbd *::before,.fd-gtbd *::after{box-sizing:border-box}
301.fd-gtbd{display:flex;align-items:center;justify-content:center;min-height:100vh;width:100%;margin:0;padding:32px 16px;overflow:hidden;color:#1d1d1f;font:400 15px/1.4 ${F};letter-spacing:normal;
302 background:radial-gradient(46% 62% at 28% 32%,#ffcfa6 0%,transparent 70%),radial-gradient(44% 58% at 74% 68%,#b7c3ff 0%,transparent 70%),radial-gradient(30% 40% at 62% 22%,#ffc2dc 0%,transparent 70%),#f1eeea}
303.fd-gtbd-stage{display:flex;justify-content:center;max-width:100%;margin:0;padding:0 0 40px}
304`;

More Liquid Glass. Same file contract.

Liquid Glass, liquid glass preview: Liquid Glass for React: a lens that refracts what is behind it, with squircle bevel, specular rim, dispersion…

Liquid Glass

Liquid Glass for React: a lens that refracts what is behind it, with squircle bevel, specular rim, dispersion and spring physics.

Glass Button, liquid glass preview: Liquid Glass button for React: glass, prominent, clear and clear-prominent capsules in four sizes, with a…

Glass Button

Liquid Glass button for React: glass, prominent, clear and clear-prominent capsules in four sizes, with a springy press.

Glass Tab Bar, liquid glass preview: iOS 26 style Liquid Glass tab bar: a lens springs between tabs, search sits apart, and the bar minimizes as…

Glass Tab Bar

iOS 26 style Liquid Glass tab bar: a lens springs between tabs, search sits apart, and the bar minimizes as you scroll.

Questions about Glass Toolbar

Run npx shadcn@latest add https://freedesignmd.com/r/glass-toolbar.json, or open the page and copy the files into your project. It has zero dependencies besides React. What you copy is the exact file that renders the live demo.

Liquid Glass toolbar for React: grouped controls with a sliding selection lens, labelled icons and a soft scroll-edge blur. It is a free, MIT-licensed React liquid glass component from the freedesignmd library.

Yes. It is free and MIT-licensed, use, modify and ship it in personal and commercial projects without attribution.

Real refraction (SVG displacement inside backdrop-filter) in Chromium browsers. Safari and Firefox fall back to a frosted blur with the same rim and highlights.

Yes. It is a plain React component with its own styles, so it runs in Next.js, Vite, Remix and Lovable projects, and it needs no Tailwind setup. It has zero dependencies besides React.