Components70 / 118
Glassy Button
A thick slab of frosted glass you can push. Hover and it rises with a jelly wobble, takes on a tint inside the glass and its shadow softens as it climbs. It tilts toward your cursor: a soft specular slides across, the label sits deeper in the glass with parallax and a faint chromatic fringe. Press to sink and squash it.
ButtonButtonGlassGlassTiltTiltSpringsSpringsSquash & stretchSquash & stretchGSAPGSAP
Hover, then move across itPress and hold
Tweak
LIVELIVEText
Look
60px
#8f86ff
Usage
Follows your tweaks.
usage.tsx
import { GlassyButton } from "@/components/inreact/glassy-button";
export function Cta() {
return <GlassyButton onClick={() => start()} size={60} />;
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/glassy-button.jsonOr copy the source
Install the dependencies, then save this as components/inreact/glassy-button.tsx.
terminal
npm install gsapcomponents/inreact/glassy-button.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef } from "react";
/**
* Glassy Button: a thick slab of frosted glass you can push.
*
* At rest it sits low on the page, a soft frosted slab with a lit lower bevel.
* Hover it and it rises (stretching as it lifts, settling with a wobble), picks
* up a tint inside the glass and throws a soft glow of it below, while its
* shadow softens and spreads the higher it goes. It tilts toward your cursor like a real slab: a soft specular slides
* across the surface, the label sits deeper inside the glass and shifts with
* parallax, and its edges split into a faint chromatic fringe, the way thick
* glass bends light. Press and it sinks and squashes; let go and it springs up.
*
* <GlassyButton label="Glassy Button" onClick={go} />
*/
export interface GlassyButtonProps {
label?: string;
href?: string;
onClick?: () => void;
/** Height, px. */
size?: number;
/** The colour the glass picks up when you hover it. */
tint?: string;
/** Text colour. */
ink?: string;
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));
export function GlassyButton({ label = "Glassy Button", href, onClick, size = 56, tint = "#8f86ff", ink = "#1b1b21", className }: GlassyButtonProps) {
const rootRef = useRef<HTMLElement | null>(null);
const slabRef = useRef<HTMLSpanElement>(null);
const tintRef = useRef<HTMLSpanElement>(null);
const specRef = useRef<HTMLSpanElement>(null);
const textRef = useRef<HTMLSpanElement>(null);
const contactRef = useRef<HTMLSpanElement>(null);
const ambientRef = useRef<HTMLSpanElement>(null);
const glowRef = useRef<HTMLSpanElement>(null);
const H = size;
useEffect(() => {
const root = rootRef.current, slab = slabRef.current, tintEl = tintRef.current, spec = specRef.current, text = textRef.current;
const contact = contactRef.current, ambient = ambientRef.current, glow = glowRef.current;
if (!root || !slab || !tintEl || !spec || !text || !contact || !ambient || !glow) return;
const still = reduced();
const st = {
lift: 0, vl: 0, tl: 0, // 0 = resting, 1 = raised
rx: 0, vrx: 0, trx: 0, // tilt, degrees
ry: 0, vry: 0, try: 0,
s: 0, vs: 0, // jelly: s > 0 stretches tall
t: 0, tt: 0, // tint
mx: 0.5, my: 0.3, // specular position (0..1)
};
const LIFT = H * 0.13;
const last = { slab: "", text: "", tint: "", spec: "", sh: "" };
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30) / 2;
for (let i = 0; i < 2; i++) {
if (still) {
st.lift = st.tl; st.rx = st.ry = 0; st.s = 0; st.t = st.tt;
break;
}
const kl = 230, cl = 2 * 0.42 * Math.sqrt(kl);
const al = kl * (st.tl - st.lift) - cl * st.vl;
st.vl += al * dt; st.lift += st.vl * dt;
const kt = 170, ct = 2 * 0.55 * Math.sqrt(kt);
st.vrx += (kt * (st.trx - st.rx) - ct * st.vrx) * dt; st.rx += st.vrx * dt;
st.vry += (kt * (st.try - st.ry) - ct * st.vry) * dt; st.ry += st.vry * dt;
// jelly: stretches while it rises fast, squashes as it lands, wobbles after
const ks = 360, cs = 2 * 0.24 * Math.sqrt(ks);
const want = clamp(-0.12, 0.12, st.vl * 0.022);
st.vs += (ks * (want - st.s) - cs * st.vs) * dt; st.s += st.vs * dt;
st.t += (st.tt - st.t) * Math.min(1, dt * 9);
}
const s = clamp(-0.14, 0.14, st.s);
const y = -st.lift * LIFT;
const tr = `translate3d(0,${y.toFixed(2)}px,0) rotateX(${st.rx.toFixed(2)}deg) rotateY(${st.ry.toFixed(2)}deg) scale(${(1 - s * 0.6).toFixed(4)},${(1 + s).toFixed(4)})`;
if (tr !== last.slab) {
slab.style.transform = tr;
last.slab = tr;
}
// the shadow: tight and dark when low, soft and wide when high
const L = clamp(0, 1.3, st.lift);
const sh = `${L.toFixed(3)}`;
if (sh !== last.sh) {
contact.style.opacity = clamp(0, 1, 1 - L * 0.85).toFixed(3);
ambient.style.opacity = clamp(0, 1, 0.35 + L * 0.65).toFixed(3);
ambient.style.transform = `translate3d(0,${(L * H * 0.16).toFixed(2)}px,0) scale(${(0.92 + L * 0.1).toFixed(3)},${(0.9 + L * 0.2).toFixed(3)})`;
// the tinted light the raised glass throws below it
glow.style.opacity = clamp(0, 0.85, L * 0.85).toFixed(3);
glow.style.transform = `translate3d(0,${(L * H * 0.1).toFixed(2)}px,0) scale(${(0.86 + L * 0.14).toFixed(3)},${(0.8 + L * 0.2).toFixed(3)})`;
last.sh = sh;
}
// the label sits deeper in the glass: parallax and a chromatic fringe with the tilt
const px = -st.ry * 0.16, py = st.rx * 0.16;
const d = Math.hypot(st.rx, st.ry);
const fa = Math.min(0.26, d * 0.045), fx = st.ry * 0.07, fy = -st.rx * 0.07;
const tx = `${px.toFixed(2)}|${py.toFixed(2)}|${fa.toFixed(3)}`;
if (tx !== last.text) {
text.style.transform = `translate3d(${px.toFixed(2)}px,${py.toFixed(2)}px,0)`;
text.style.textShadow =
fa > 0.01 ? `${fx.toFixed(2)}px ${fy.toFixed(2)}px 0 rgba(255,40,90,${fa.toFixed(3)}), ${(-fx).toFixed(2)}px ${(-fy).toFixed(2)}px 0 rgba(30,120,255,${fa.toFixed(3)})` : "none";
last.text = tx;
}
const ti = st.t.toFixed(3);
if (ti !== last.tint) {
tintEl.style.opacity = ti;
last.tint = ti;
}
const sp = `${st.mx.toFixed(3)}|${st.my.toFixed(3)}|${st.t.toFixed(2)}`;
if (sp !== last.spec) {
spec.style.transform = `translate3d(${((st.mx - 0.5) * 100).toFixed(2)}%,${((st.my - 0.5) * 100).toFixed(2)}%,0)`;
spec.style.opacity = (0.35 + st.t * 0.65).toFixed(3);
last.spec = sp;
}
};
gsap.ticker.add(tick);
let box = root.getBoundingClientRect();
let pressed = false;
const onEnter = () => {
box = root.getBoundingClientRect();
st.tl = 1;
st.tt = 1;
};
const onLeave = () => {
st.tl = 0;
st.tt = 0;
st.trx = st.try = 0;
st.mx = 0.5;
st.my = 0.3;
pressed = false;
};
const onMove = (e: PointerEvent) => {
const nx = clamp(0, 1, (e.clientX - box.left) / box.width), ny = clamp(0, 1, (e.clientY - box.top) / box.height);
st.mx = nx;
st.my = ny;
// the near edge dips toward you
st.try = (nx - 0.5) * 9;
st.trx = -(ny - 0.5) * 11;
};
const onDown = () => {
pressed = true;
st.tl = 0.12; // sinks
st.vs -= 2.6; // and squashes
};
const onUp = () => {
if (!pressed) return;
pressed = false;
st.tl = 1;
st.vs += 1.4;
};
root.addEventListener("pointerenter", onEnter);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerdown", onDown);
root.addEventListener("pointerup", onUp);
// keyboard focus lifts it too (a mouse press focuses it as well, so skip that)
const onFocus = () => root.matches(":focus-visible") && onEnter();
const onBlur = () => !root.matches(":hover") && onLeave();
root.addEventListener("focus", onFocus);
root.addEventListener("blur", onBlur);
return () => {
gsap.ticker.remove(tick);
root.removeEventListener("pointerenter", onEnter);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerdown", onDown);
root.removeEventListener("pointerup", onUp);
root.removeEventListener("focus", onFocus);
root.removeEventListener("blur", onBlur);
};
}, [H]);
const r = Math.round(H * 0.4);
const cls = ["relative inline-grid shrink-0 select-none place-items-center outline-none [-webkit-tap-highlight-color:transparent] [perspective:700px]", className].filter(Boolean).join(" ");
const style = { height: H, color: ink } as const;
const inner = (
<>
{/* shadows: neutral, layered, soft; one hugs the slab, one spreads as it rises */}
<span
ref={contactRef}
aria-hidden="true"
className="pointer-events-none absolute will-change-[opacity]"
style={{ left: "7%", right: "7%", bottom: -2, height: "45%", borderRadius: r, background: "rgba(24,24,44,.2)", filter: "blur(5px)" }}
/>
<span
ref={ambientRef}
aria-hidden="true"
className="pointer-events-none absolute will-change-[transform,opacity]"
style={{ left: "5%", right: "5%", bottom: "-14%", height: "70%", borderRadius: r, opacity: 0.35, background: "rgba(24,24,44,.16)", filter: "blur(16px)" }}
/>
<span
ref={glowRef}
aria-hidden="true"
className="pointer-events-none absolute opacity-0 will-change-[transform,opacity]"
style={{ left: "8%", right: "8%", bottom: "-9%", height: "46%", borderRadius: r, background: `color-mix(in srgb, ${tint} 50%, transparent)`, filter: `blur(${Math.round(H * 0.2)}px)` }}
/>
{/* the slab */}
<span
ref={slabRef}
className="relative grid h-full place-items-center overflow-hidden will-change-transform [backdrop-filter:blur(12px)_saturate(1.4)] group-focus-visible/glass:ring-2 group-focus-visible/glass:ring-black/20"
style={{
padding: `0 ${Math.round(H * 0.5)}px`,
borderRadius: r,
transformOrigin: "50% 100%",
background: "linear-gradient(180deg, rgba(255,255,255,.62) 0%, rgba(240,240,245,.5) 55%, rgba(228,228,236,.58) 100%)",
// the bevel: a lit top edge, a bright lower lip, and the slab's thickness shading in
boxShadow:
"inset 0 1.5px 1px rgba(255,255,255,.95), inset 0 -2px 2px rgba(255,255,255,.9), inset 0 -5px 9px rgba(140,140,165,.16), inset 0 6px 14px rgba(255,255,255,.35), inset 2px 0 6px rgba(150,150,170,.1), inset -2px 0 6px rgba(150,150,170,.1)",
}}
>
{/* tint inside the glass */}
<span
ref={tintRef}
aria-hidden="true"
className="pointer-events-none absolute inset-0 opacity-0 will-change-[opacity]"
style={{ background: `linear-gradient(180deg, color-mix(in srgb, ${tint} 10%, transparent), color-mix(in srgb, ${tint} 22%, transparent))` }}
/>
{/* the slab's top face, set in from the bevel: a gentle band of thickness around the edge */}
<span
aria-hidden="true"
className="pointer-events-none absolute"
style={{
inset: Math.max(2, Math.round(H * 0.06)),
borderRadius: Math.max(2, r - Math.round(H * 0.06)),
background: "linear-gradient(180deg, rgba(255,255,255,.5) 0%, rgba(255,255,255,.14) 60%, rgba(255,255,255,.04) 100%)",
boxShadow: "0 1px 2px rgba(255,255,255,.55), 0 -1px 3px rgba(120,120,150,.1), inset 0 1px 1px rgba(255,255,255,.7)",
}}
/>
{/* a soft specular that slides with your cursor */}
<span aria-hidden="true" className="pointer-events-none absolute inset-0 overflow-hidden" style={{ borderRadius: r }}>
<span
ref={specRef}
className="absolute will-change-[transform,opacity]"
style={{ inset: "-50%", opacity: 0.35, background: "radial-gradient(28% 40% at 50% 50%, rgba(255,255,255,.75), rgba(255,255,255,0) 70%)" }}
/>
</span>
<span ref={textRef} className="relative whitespace-nowrap will-change-transform" style={{ fontSize: Math.round(H * 0.32), fontWeight: 500, letterSpacing: "-0.01em" }}>
{label}
</span>
</span>
</>
);
return href ? (
<a ref={(el) => void (rootRef.current = el)} href={href} onClick={onClick} className={`group/glass ${cls}`} style={style}>
{inner}
</a>
) : (
<button ref={(el) => void (rootRef.current = el)} type="button" onClick={onClick} className={`group/glass ${cls}`} style={style}>
{inner}
</button>
);
}
export default GlassyButton;
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
7 propslabelstringButton text.default "Glassy Button"default "Glassy Button"hrefstringRender a link.onClick() => voidClick handler.sizenumberHeight, px.default 56default 56tintstringThe colour the glass picks up on hover.default "#8f86ff"default "#8f86ff"inkstringText colour.default "#1b1b21"default "#1b1b21"classNamestringExtra classes.