Components91 / 118
Glass Nav
A floating navigation bar of soft, borderless frosted glass that rises in with an overshoot. A frosted lens glides under the links on a spring, stretching and squashing as it goes; the sun / moon knob hops across and jiggles as the bar breathes into its new tint; the button leans toward your cursor and presses like jelly.
NavigationNavigationHeaderHeaderFrosted glassFrosted glassTheme toggleTheme toggleSpringsSpringsAnimation principlesAnimation principlesGSAPGSAP

Point at the linksFlip the sun / moon switch
Tweak
LIVELIVELook
Theme
56px
22px
Usage
Follows your tweaks.
usage.tsx
import { GlassNav } from "@/components/inreact/glass-nav";
export function Hero() {
return (
<section className="relative h-screen">
<img src="/hero.jpg" alt="" className="absolute inset-0 size-full object-cover" />
<div className="absolute inset-x-0 bottom-16 flex justify-center">
<GlassNav
brand="Altura"
links={[{ label: "Services", href: "/services" }, { label: "Industries", href: "/industries" }, { label: "News", href: "/news" }, { label: "Contact", href: "/contact" }]}
cta={{ label: "Get Started", href: "/start" }}
/>
</div>
</section>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/glass-nav.jsonOr copy the source
Install the dependencies, then save this as components/inreact/glass-nav.tsx.
terminal
npm install gsapcomponents/inreact/glass-nav.tsx
"use client";
import { gsap } from "gsap";
import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
/**
* Glass Nav: a floating navigation bar of frosted glass.
*
* Soft, borderless frosted glass: whatever is behind it (any page, photo or
* video) is blurred deep and smoked, with a fine frost grain and a barely
* there sheen that drifts with your cursor. No outlines anywhere.
*
* Everything moves with the principles of animation. The bar rises in with
* a little wind-up, overshoots and settles while its contents follow a beat
* behind. A frosted lens rides under the links: point at one and it glides
* over on a spring, stretching with its speed, squashing as it lands and
* settling with a small bounce. The sun / moon knob hops across in an arc and
* jiggles as it lands while the whole bar breathes into its new tint. The
* button leans toward your cursor, its arrow slides in, and it presses like
* jelly. On narrow screens the links pour out of the bar as a menu.
*
* <GlassNav brand="Altura" links={[{ label: "Services", href: "/services" }, ...]} cta={{ label: "Get Started", href: "/start" }} />
*/
export interface GlassNavLink {
label: string;
href?: string;
}
export interface GlassNavProps {
brand?: string;
/** Your mark (defaults to a simple glyph). */
logo?: ReactNode;
links?: GlassNavLink[];
cta?: { label: string; href?: string };
theme?: "dark" | "light";
defaultTheme?: "dark" | "light";
onThemeChange?: (t: "dark" | "light") => void;
/** Bar height, px. */
size?: number;
/** How deep the frost is, px of blur. */
frost?: number;
className?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clamp = (a: number, b: number, v: number) => Math.max(a, Math.min(b, v));
type Spring = { x: number; v: number; t: number };
const step = (b: Spring, k: number, c: number, h: number) => {
for (let i = 0; i < 2; i++) (b.v += (k * (b.t - b.x) - c * b.v) * (h / 2)), (b.x += b.v * (h / 2));
};
// fine frost grain (tiny, tiled)
const GRAIN =
"url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>\")";
const EASE_OUT = "cubic-bezier(.22,1,.36,1)";
function Mark() {
return (
<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor" aria-hidden="true">
<path d="M12 2.5c3.4 2.6 5.4 5.6 5.4 8.6 0 2.1-1 3.9-2.7 5l3.4 5.4H5.9l3.4-5.4c-1.7-1.1-2.7-2.9-2.7-5 0-3 2-6 5.4-8.6Zm0 4.2c-1.7 1.6-2.6 3.1-2.6 4.6 0 1.4 1.2 2.6 2.6 2.6s2.6-1.2 2.6-2.6c0-1.5-.9-3-2.6-4.6Z" />
</svg>
);
}
export function GlassNav({
brand = "Altura",
logo,
links = [{ label: "Services" }, { label: "Industries" }, { label: "News" }, { label: "Contact" }],
cta = { label: "Get Started" },
theme,
defaultTheme = "dark",
onThemeChange,
size = 56,
frost = 22,
className,
}: GlassNavProps) {
const rootRef = useRef<HTMLElement>(null);
const glassRef = useRef<HTMLDivElement>(null);
const sheenRef = useRef<HTMLDivElement>(null);
const lensRef = useRef<HTMLSpanElement>(null);
const rowRef = useRef<HTMLDivElement>(null);
const linkRefs = useRef<(HTMLAnchorElement | null)[]>([]);
const knobRef = useRef<HTMLSpanElement>(null);
const ctaRef = useRef<HTMLAnchorElement>(null);
const menuRef = useRef<HTMLDivElement>(null);
const [inner, setInner] = useState<"dark" | "light">(defaultTheme);
const mode = theme ?? inner;
const dark = mode === "dark";
const [narrow, setNarrow] = useState(false);
const [open, setOpen] = useState(false);
const api = useRef<{ lensTo: (i: number) => void }>({ lensTo: () => {} });
const H = size;
const setMode = useCallback(
(t: "dark" | "light") => {
if (theme === undefined) setInner(t);
onThemeChange?.(t);
},
[theme, onThemeChange],
);
// fold the links away when there isn't room
useEffect(() => {
const el = rootRef.current?.parentElement;
if (!el) return;
const ro = new ResizeObserver(([e]) => setNarrow(e.contentRect.width < H * 11));
ro.observe(el);
return () => ro.disconnect();
}, [H]);
// entrance: a little wind-up, a rise with overshoot, contents a beat behind
useEffect(() => {
const root = rootRef.current, row = rowRef.current;
if (!root || !row || reduced()) return;
const kids = Array.from(row.children);
const tl = gsap.timeline();
tl.fromTo(root, { y: H * 0.5, scaleX: 0.86, scaleY: 0.7, opacity: 0 }, { y: H * 0.08, scaleX: 1.03, scaleY: 0.94, opacity: 1, duration: 0.42, ease: "power3.out" })
.to(root, { y: 0, scaleX: 1, scaleY: 1, duration: 0.9, ease: "elastic.out(1, 0.5)" })
.fromTo(kids, { y: H * 0.18, opacity: 0 }, { y: 0, opacity: 1, duration: 0.7, ease: "back.out(2)", stagger: 0.045 }, 0.18);
return () => void tl.kill();
}, [H]);
// the lens and the sheen run on springs
useEffect(() => {
const root = rootRef.current, lens = lensRef.current, sheen = sheenRef.current;
if (!root || !lens || !sheen) return;
const still = reduced();
const x: Spring = { x: 0, v: 0, t: 0 }, w: Spring = { x: 40, v: 0, t: 40 }, a: Spring = { x: 0, v: 0, t: 0 };
const sx: Spring = { x: 0.3, v: 0, t: 0.3 }, so: Spring = { x: 0, v: 0, t: 0 };
const sq: Spring = { x: 0, v: 0, t: 0 };
let idx = -1, last = "";
const lensTo = (i: number) => {
const prev = idx;
idx = i;
const el = i >= 0 ? linkRefs.current[i] : null;
if (!el || !el.offsetParent) {
a.t = 0;
return;
}
// measured from the lens's own frame (the links group), so it lands exactly under the link
const r = el.getBoundingClientRect(), rr = (lens.parentElement ?? root).getBoundingClientRect();
const cx = r.left - rr.left + r.width / 2;
if (prev < 0 && a.x < 0.05) (x.x = cx), (w.x = r.width * 0.7); // appears where you point
x.t = cx;
w.t = r.width + H * 0.32;
a.t = 1;
if (!still && prev < 0) a.v += 3; // pops in with a little overshoot
};
api.current.lensTo = lensTo;
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
const px = x.x;
if (still) (x.x = x.t), (w.x = w.t), (a.x = a.t), (sx.x = sx.t), (so.x = so.t);
else {
step(x, 210, 17, dt); // glides over, overshoots a touch and settles
step(w, 170, 13, dt);
step(a, 190, 15, dt);
step(sx, 45, 11, dt);
step(so, 60, 14, dt);
}
const vx = (x.x - px) / Math.max(dt, 1e-3);
sq.t = still ? 0 : clamp(-0.25, 0.35, Math.abs(vx) / 1800);
if (!still) step(sq, 260, 10, dt); // stretch in flight, squash + bounce as it lands
const s = sq.x, al = clamp(0, 1.15, a.x);
const lw = Math.max(8, w.x);
const key = `${x.x.toFixed(1)}|${lw.toFixed(1)}|${al.toFixed(3)}|${s.toFixed(3)}|${sx.x.toFixed(3)}|${so.x.toFixed(3)}`;
if (key === last) return;
last = key;
lens.style.width = `${lw.toFixed(1)}px`;
lens.style.transform = `translate3d(${(x.x - lw / 2).toFixed(1)}px,-50%,0) scale(${((1 + s) * (0.75 + 0.25 * al)).toFixed(3)},${((1 / (1 + s * 0.7)) * (0.6 + 0.4 * al)).toFixed(3)})`;
lens.style.opacity = clamp(0, 1, al).toFixed(3);
// a soft sheen that drifts with the cursor
sheen.style.opacity = (0.55 + 0.45 * so.x).toFixed(3);
sheen.style.backgroundPosition = `${(sx.x * 100).toFixed(1)}% 0%`;
// the link under the lens lifts a touch
linkRefs.current.forEach((el, i) => {
if (!el) return;
const on = i === idx ? clamp(0, 1, a.x) : 0;
el.style.transform = on ? `translateY(${(-0.6 * on).toFixed(2)}px)` : "";
el.style.opacity = String(0.82 + 0.18 * on);
});
};
gsap.ticker.add(tick);
const onMove = (e: PointerEvent) => {
const r = root.getBoundingClientRect();
sx.t = clamp(0, 1, (e.clientX - r.left) / r.width);
so.t = 1;
};
const onLeave = () => {
so.t = 0;
lensTo(-1);
};
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerleave", onLeave);
return () => {
gsap.ticker.remove(tick);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerleave", onLeave);
};
}, [H]);
// theme: the knob hops across in an arc and jiggles as it lands; the bar breathes into its new tint
const first = useRef(true);
useEffect(() => {
const k = knobRef.current, root = rootRef.current;
if (!k || !root) return;
const xTo = dark ? H * 0.34 : 0;
if (first.current || reduced()) {
first.current = false;
gsap.set(k, { x: xTo });
return;
}
gsap
.timeline()
.to(k, { scaleX: 1.18, scaleY: 0.82, duration: 0.1, ease: "power2.in" }) // wind-up
.to(k, { x: xTo, duration: 0.42, ease: "power3.inOut" })
.to(k, { y: -H * 0.08, scaleX: 0.9, scaleY: 1.12, duration: 0.21, ease: "power2.out" }, "<")
.to(k, { y: 0, scaleX: 1.22, scaleY: 0.8, duration: 0.2, ease: "power2.in" }, ">")
.to(k, { scaleX: 1, scaleY: 1, duration: 0.7, ease: "elastic.out(1.1, 0.38)" });
gsap.timeline().to(root, { scale: 1.018, duration: 0.25, ease: "power2.out" }).to(root, { scale: 1, duration: 0.8, ease: "elastic.out(1, 0.45)" });
}, [dark, H]);
// the button leans toward your cursor and presses like jelly
useEffect(() => {
const b = ctaRef.current;
if (!b || reduced()) return;
const qx = gsap.quickTo(b, "x", { duration: 0.5, ease: "elastic.out(1, 0.5)" });
const qy = gsap.quickTo(b, "y", { duration: 0.5, ease: "elastic.out(1, 0.5)" });
const move = (e: PointerEvent) => {
const r = b.getBoundingClientRect();
qx(((e.clientX - (r.left + r.width / 2)) / r.width) * H * 0.16);
qy(((e.clientY - (r.top + r.height / 2)) / r.height) * H * 0.08);
};
const leave = () => (qx(0), qy(0));
b.addEventListener("pointermove", move);
b.addEventListener("pointerleave", leave);
return () => {
b.removeEventListener("pointermove", move);
b.removeEventListener("pointerleave", leave);
};
}, [H]);
// the menu pours open with a bounce (narrow screens)
useEffect(() => {
const m = menuRef.current;
if (!m) return;
const items = m.querySelectorAll("li");
if (reduced()) {
gsap.set(m, { height: open ? "auto" : 0 });
return;
}
if (open) {
gsap.fromTo(m, { height: 0 }, { height: "auto", duration: 0.7, ease: "elastic.out(1, 0.6)" });
gsap.fromTo(items, { y: -10, opacity: 0 }, { y: 0, opacity: 1, duration: 0.5, ease: "back.out(2)", stagger: 0.05, delay: 0.05 });
} else gsap.to(m, { height: 0, duration: 0.35, ease: "power3.inOut" });
}, [open]);
const press = (el: HTMLElement) => {
if (reduced()) return;
gsap.fromTo(el, { scaleX: 1.08, scaleY: 0.88 }, { scaleX: 1, scaleY: 1, duration: 0.65, ease: "elastic.out(1, 0.35)" });
};
const fg = dark ? "#ffffff" : "#121316";
const fs = Math.round(H * 0.245);
return (
<nav
ref={rootRef}
aria-label="Main"
className={["relative isolate inline-flex flex-col overflow-hidden", className].filter(Boolean).join(" ")}
style={{ color: fg, borderRadius: H / 2, fontSize: fs, transition: `color .6s ${EASE_OUT}`, boxShadow: dark ? "0 10px 30px -12px rgba(10,14,22,.35)" : "0 10px 30px -14px rgba(10,14,22,.22)" }}
>
{/* the frosted glass: deep blur of whatever is behind, smoked or milky, with grain and a drifting sheen; no outlines */}
<div
ref={glassRef}
aria-hidden="true"
className="pointer-events-none absolute inset-0 -z-10"
style={{
backdropFilter: `blur(${frost}px) saturate(1.5)`,
WebkitBackdropFilter: `blur(${frost}px) saturate(1.5)`,
background: dark ? "rgba(22,24,30,.46)" : "rgba(246,247,249,.58)",
transition: `background .6s ${EASE_OUT}`,
}}
/>
<div aria-hidden="true" className="pointer-events-none absolute inset-0 -z-10" style={{ backgroundImage: GRAIN, opacity: dark ? 0.07 : 0.1, mixBlendMode: "overlay" }} />
<div
ref={sheenRef}
aria-hidden="true"
className="pointer-events-none absolute inset-0 -z-10"
style={{ backgroundImage: `radial-gradient(60% 140% at 50% -40%, rgba(255,255,255,${dark ? 0.16 : 0.5}), transparent 70%)`, backgroundSize: "200% 100%", backgroundRepeat: "no-repeat" }}
/>
<div ref={rowRef} className="relative flex items-center" style={{ height: H, paddingLeft: H * 0.36, paddingRight: H * 0.13, gap: H * 0.3 }}>
<a href="#" onClick={(e) => e.preventDefault()} className="flex shrink-0 items-center font-semibold tracking-[-0.01em] no-underline" style={{ gap: H * 0.14, fontSize: fs * 1.08, color: "inherit" }}>
<span style={{ fontSize: fs * 1.35, lineHeight: 0 }}>{logo ?? <Mark />}</span>
{brand}
</a>
{!narrow && (
<>
<span aria-hidden="true" className="shrink-0" style={{ width: 1, height: H * 0.38, background: "currentColor", opacity: 0.18 }} />
<div className="relative">
{/* the frosted lens under the links */}
<span
ref={lensRef}
aria-hidden="true"
className="pointer-events-none absolute top-1/2 left-0 rounded-full"
style={{ height: H * 0.66, opacity: 0, background: dark ? "rgba(255,255,255,.13)" : "rgba(255,255,255,.75)", boxShadow: dark ? "0 4px 14px -6px rgba(0,0,0,.35)" : "0 4px 14px -6px rgba(20,30,50,.18)", transformOrigin: "50% 50%" }}
/>
<ul className="relative m-0 flex list-none items-center p-0" style={{ gap: H * 0.04 }} onPointerLeave={() => api.current.lensTo(-1)}>
{links.map((l, i) => (
<li key={l.label}>
<a
ref={(el) => void (linkRefs.current[i] = el)}
href={l.href ?? "#"}
onClick={(e) => !l.href && e.preventDefault()}
onPointerEnter={() => api.current.lensTo(i)}
onFocus={() => api.current.lensTo(i)}
onBlur={() => api.current.lensTo(-1)}
className="block whitespace-nowrap no-underline outline-none"
style={{ color: "inherit", padding: `${H * 0.13}px ${H * 0.21}px`, opacity: 0.82 }}
>
{l.label}
</a>
</li>
))}
</ul>
</div>
</>
)}
<span className="flex-1" style={{ minWidth: H * 0.3 }} />
{/* sun / moon */}
<button
type="button"
role="switch"
aria-checked={dark}
aria-label="Dark mode"
onClick={(e) => {
setMode(dark ? "light" : "dark");
press(e.currentTarget);
}}
className="relative grid shrink-0 cursor-pointer grid-cols-2 place-items-center rounded-full border-0 p-0 outline-none focus-visible:ring-2 focus-visible:ring-current/40"
style={{ width: H * 0.74, height: H * 0.42, background: dark ? "rgba(255,255,255,.1)" : "rgba(0,0,0,.06)", color: "inherit", transition: `background .6s ${EASE_OUT}` }}
>
<span ref={knobRef} aria-hidden="true" className="absolute rounded-full" style={{ left: H * 0.03, top: H * 0.03, width: H * 0.36, height: H * 0.36, background: "#ffffff", boxShadow: "0 1px 2px rgba(0,0,0,.16), 0 4px 10px -2px rgba(0,0,0,.18)", transformOrigin: "50% 100%" }} />
<svg viewBox="0 0 24 24" width={H * 0.22} height={H * 0.22} fill="none" stroke={dark ? "currentColor" : "#121316"} strokeWidth="2.2" strokeLinecap="round" aria-hidden="true" style={{ position: "relative", opacity: dark ? 0.6 : 1, transition: `opacity .4s` }}>
<circle cx="12" cy="12" r="4.2" />
<path d="M12 2.5v2.2M12 19.3v2.2M2.5 12h2.2M19.3 12h2.2M5.3 5.3l1.5 1.5M17.2 17.2l1.5 1.5M5.3 18.7l1.5-1.5M17.2 6.8l1.5-1.5" />
</svg>
<svg viewBox="0 0 24 24" width={H * 0.2} height={H * 0.2} fill={dark ? "#121316" : "currentColor"} aria-hidden="true" style={{ position: "relative", opacity: dark ? 1 : 0.5, transition: `opacity .4s` }}>
<path d="M20.5 14.6A8.5 8.5 0 0 1 9.4 3.5a8.5 8.5 0 1 0 11.1 11.1Z" />
</svg>
</button>
{narrow && (
<button
type="button"
aria-expanded={open}
aria-label="Menu"
onClick={(e) => {
setOpen((o) => !o);
press(e.currentTarget);
}}
className="grid shrink-0 cursor-pointer place-items-center rounded-full border-0 bg-transparent p-0 outline-none"
style={{ width: H * 0.6, height: H * 0.6, color: "inherit" }}
>
<svg viewBox="0 0 24 24" width={H * 0.34} height={H * 0.34} fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden="true">
<path d={open ? "M6 6l12 12M18 6 6 18" : "M4 9h16M4 15h16"} />
</svg>
</button>
)}
{/* the button */}
<a
ref={ctaRef}
href={cta.href ?? "#"}
onClick={(e) => {
if (!cta.href) e.preventDefault();
press(e.currentTarget);
}}
className="group relative inline-flex shrink-0 items-center overflow-hidden rounded-full font-medium no-underline"
style={{ height: H * 0.72, padding: `0 ${H * 0.38}px`, fontSize: fs * 0.95, background: dark ? "#ffffff" : "#121316", color: dark ? "#121316" : "#ffffff", transition: `background .6s ${EASE_OUT}, color .6s ${EASE_OUT}` }}
>
<span className="transition-transform duration-500 group-hover:-translate-x-[0.4em]" style={{ transitionTimingFunction: "cubic-bezier(.34,1.56,.64,1)" }}>
{cta.label}
</span>
<svg viewBox="0 0 24 24" width="0.95em" height="0.95em" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" className="absolute translate-x-[-0.6em] opacity-0 transition-all duration-500 group-hover:translate-x-0 group-hover:opacity-100" style={{ right: H * 0.2, transitionTimingFunction: "cubic-bezier(.34,1.56,.64,1)" }}>
<path d="M5 12h13M13 6l6 6-6 6" />
</svg>
</a>
</div>
{/* narrow: the links pour out of the bar */}
{narrow && (
<div ref={menuRef} className="overflow-hidden" style={{ height: 0 }}>
<ul className="m-0 list-none" style={{ padding: `0 ${H * 0.36}px ${H * 0.3}px` }}>
{links.map((l) => (
<li key={l.label}>
<a href={l.href ?? "#"} onClick={(e) => !l.href && e.preventDefault()} className="block no-underline" style={{ color: "inherit", padding: `${H * 0.12}px 0`, fontSize: fs * 1.15 }}>
{l.label}
</a>
</li>
))}
</ul>
</div>
)}
</nav>
);
}
export default GlassNav;
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
10 propsbrandstringYour name.default "Altura"default "Altura"logoReactNodeYour mark (defaults to a simple glyph).links{ label: string; href?: string }[]The links.cta{ label: string; href?: string }The button.default { label: "Get Started" }default { label: "Get Started" }theme"dark" | "light"Controlled theme.defaultTheme"dark" | "light"Starting theme.default "dark"default "dark"onThemeChange(theme) => voidCalled when the switch flips.sizenumberBar height, px.default 56default 56frostnumberHow deep the frost is (px of blur).default 22default 22classNamestringExtra classes.