Components71 / 118
Liquid Light Button
A dark glass button with a pool of light inside. The light follows your cursor like a liquid, warming from violet to blue across the button and lighting the hairline edge as it passes; it stretches when you move fast, settles with a squash and drains out the edge you leave by. Click for a ripple of light.
ButtonButtonCursor lightCursor lightGradient borderGradient borderSpringsSpringsSquash & stretchSquash & stretchGSAPGSAP
Sweep across it, fast and slowClick for a ripple
Tweak
LIVELIVEText
Look
64px
Light
#8b2cf5
#2f55ff
Usage
Follows your tweaks.
usage.tsx
import { LiquidLightButton } from "@/components/inreact/liquid-light-button";
export function Cta() {
return <LiquidLightButton onClick={() => start()} size={64} />;
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/liquid-light-button.jsonOr copy the source
Install the dependencies, then save this as components/inreact/liquid-light-button.tsx.
terminal
npm install gsapcomponents/inreact/liquid-light-button.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef } from "react";
/**
* Liquid Light Button: a dark glass button with a pool of light inside.
*
* Move over it and a pool of coloured light follows your cursor through the
* glass, warming from violet on the left to blue on the right and lighting the
* hairline edge as it passes. The light is a liquid: it trails with inertia,
* stretches along its path when you move fast, squashes as it settles, and
* when you leave it drains out through the edge you left by. Click and a
* ripple of light runs out to the border; the button itself squashes and
* springs back. GSAP.
*
* <LiquidLightButton label="Button" onClick={go} />
*/
export interface LiquidLightButtonProps {
label?: string;
href?: string;
onClick?: () => void;
/** Height, px. */
size?: number;
/** The light on the left. */
from?: string;
/** The light on the right. */
to?: 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 LiquidLightButton({ label = "Button", href, onClick, size = 56, from = "#8b2cf5", to = "#2f55ff", className }: LiquidLightButtonProps) {
const rootRef = useRef<HTMLElement | null>(null);
const bodyRef = useRef<HTMLSpanElement>(null);
const textRef = useRef<HTMLSpanElement>(null);
const blobs = useRef<(HTMLSpanElement | null)[]>([]); // [inner, edge]
const ripples = useRef<(HTMLSpanElement | null)[]>([]); // [inner, edge]
const H = size;
const D = Math.round(H * 1.9); // the pool's diameter
useEffect(() => {
const root = rootRef.current, body = bodyRef.current, text = textRef.current;
if (!root || !body || !text) return;
const still = reduced();
const st = {
x: 0, y: 0, vx: 0, vy: 0, tx: 0, ty: 0, // the pool, px inside the button
i: 0, ti: 0, // intensity
s: 0, a: 0, // stretch along the travel, and its angle
js: 0, jv: 0, // the button's own jelly (press)
};
let box = root.getBoundingClientRect();
let inside = false;
const last = { blob: "", body: "", text: "" };
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30) / 2;
for (let k = 0; k < 2; k++) {
if (still) {
st.x = st.tx; st.y = st.ty; st.i = st.ti; st.vx = st.vy = 0; st.js = 0;
break;
}
// a liquid: follows with inertia, a little overshoot
const kk = 95, c = 2 * 0.58 * Math.sqrt(kk);
st.vx += (kk * (st.tx - st.x) - c * st.vx) * dt; st.x += st.vx * dt;
st.vy += (kk * (st.ty - st.y) - c * st.vy) * dt; st.y += st.vy * dt;
st.i += (st.ti - st.i) * Math.min(1, dt * (st.ti > st.i ? 7 : 3.2));
const kj = 420, cj = 2 * 0.24 * Math.sqrt(kj);
st.jv += (-kj * st.js - cj * st.jv) * dt; st.js += st.jv * dt;
}
// stretch along the motion; it settles back round with a squash
const sp = Math.hypot(st.vx, st.vy);
const want = still ? 0 : Math.min(0.75, sp * 0.0016);
st.s += (want - st.s) * Math.min(1, (ms / 1000) * (want > st.s ? 14 : 7));
if (sp > 25) {
const ang = (Math.atan2(st.vy, st.vx) * 180) / Math.PI;
const d = ((((ang - st.a + 90) % 180) + 180) % 180) - 90;
st.a += d * Math.min(1, (ms / 1000) * 18);
}
const sx = 1 + st.s, sy = 1 / Math.sqrt(1 + st.s * 1.6);
// violet on the left, blue on the right
const hue = clamp(0, 1, st.x / Math.max(1, box.width));
const tr = `translate3d(${(st.x - D / 2).toFixed(2)}px,${(st.y - D / 2).toFixed(2)}px,0) rotate(${st.a.toFixed(2)}deg) scale(${sx.toFixed(4)},${sy.toFixed(4)})`;
const key = `${tr}|${st.i.toFixed(3)}|${hue.toFixed(3)}`;
if (key !== last.blob) {
for (const b of blobs.current) {
if (!b) continue;
b.style.transform = tr;
b.style.opacity = st.i.toFixed(3);
(b.lastElementChild as HTMLElement).style.opacity = hue.toFixed(3);
}
last.blob = key;
}
const js = clamp(-0.12, 0.12, st.js);
const bt = `scale(${(1 + js * 0.6).toFixed(4)},${(1 - js).toFixed(4)})`;
if (bt !== last.body) {
body.style.transform = bt;
last.body = bt;
}
// the label leans a hair toward the light
const lx = ((st.x / Math.max(1, box.width)) - 0.5) * 2 * st.i, ly = ((st.y / Math.max(1, box.height)) - 0.5) * 2 * st.i;
const tt = `translate3d(${(lx * H * 0.03).toFixed(2)}px,${(ly * H * 0.02).toFixed(2)}px,0)`;
if (tt !== last.text) {
text.style.transform = tt;
last.text = tt;
}
};
gsap.ticker.add(tick);
const local = (e: PointerEvent) => ({ x: e.clientX - box.left, y: e.clientY - box.top });
const onEnter = (e: PointerEvent) => {
box = root.getBoundingClientRect();
inside = true;
const p = local(e);
// the light appears where you come in (if it had drained away)
if (st.i < 0.08) {
st.x = p.x;
st.y = p.y;
st.vx = st.vy = 0;
}
st.tx = p.x;
st.ty = p.y;
st.ti = 1;
};
const onMove = (e: PointerEvent) => {
if (!inside) return;
const p = local(e);
st.tx = p.x;
st.ty = p.y;
};
const onLeave = (e: PointerEvent) => {
inside = false;
const p = local(e);
// drain out through the edge you left by
const cx = box.width / 2, cy = box.height / 2;
const dx = p.x - cx, dy = p.y - cy, d = Math.hypot(dx, dy) || 1;
st.tx = p.x + (dx / d) * H * 0.9;
st.ty = p.y + (dy / d) * H * 0.9;
st.ti = 0;
};
const onDown = (e: PointerEvent) => {
if (still) return;
st.jv -= 2.6; // squash
const p = local(e);
for (const r of ripples.current) {
if (!r) continue;
gsap.killTweensOf(r);
gsap.fromTo(
r,
{ x: p.x - D / 2, y: p.y - D / 2, scale: 0.15, opacity: 1 },
{ scale: (box.width * 2.4) / D, opacity: 0, duration: 0.9, ease: "power2.out" },
);
}
};
const onUp = () => {
if (!still) st.jv += 1.8;
};
const onFocus = () => {
if (!root.matches(":focus-visible")) return;
box = root.getBoundingClientRect();
st.x = st.tx = box.width / 2;
st.y = st.ty = box.height / 2;
st.ti = 0.8;
};
const onBlur = () => {
if (!inside) st.ti = 0;
};
root.addEventListener("pointerenter", onEnter);
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("pointerdown", onDown);
root.addEventListener("pointerup", onUp);
root.addEventListener("focus", onFocus);
root.addEventListener("blur", onBlur);
return () => {
gsap.ticker.remove(tick);
ripples.current.forEach((r) => r && gsap.killTweensOf(r));
root.removeEventListener("pointerenter", onEnter);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("pointerdown", onDown);
root.removeEventListener("pointerup", onUp);
root.removeEventListener("focus", onFocus);
root.removeEventListener("blur", onBlur);
};
}, [D, H]);
const r = Math.round(H * 0.24);
// a blob of light: violet underneath, blue on top (cross-faded by position)
const pool = (k: number, strength: number) => (
<span
ref={(el) => void (blobs.current[k] = el)}
aria-hidden="true"
className="pointer-events-none absolute top-0 left-0 opacity-0 will-change-[transform,opacity]"
style={{ width: D, height: D }}
>
<span className="absolute inset-0 rounded-full" style={{ background: `radial-gradient(closest-side, color-mix(in srgb, ${from} ${strength}%, transparent), transparent)` }} />
<span className="absolute inset-0 rounded-full opacity-0" style={{ background: `radial-gradient(closest-side, color-mix(in srgb, ${to} ${strength}%, transparent), transparent)` }} />
</span>
);
const ripple = (k: number, strength: number) => (
<span
ref={(el) => void (ripples.current[k] = el)}
aria-hidden="true"
className="pointer-events-none absolute top-0 left-0 rounded-full opacity-0 will-change-[transform,opacity]"
style={{ width: D, height: D, background: `radial-gradient(closest-side, transparent 62%, color-mix(in srgb, ${to} ${strength}%, transparent) 80%, transparent)` }}
/>
);
// the hairline edge: a 1px ring (mask) the light can pass under
const ring = {
borderRadius: r,
padding: 1,
WebkitMask: "linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)",
WebkitMaskComposite: "xor",
mask: "linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0)",
} as const;
const cls = ["group/ll relative inline-grid shrink-0 select-none place-items-center outline-none [-webkit-tap-highlight-color:transparent]", className].filter(Boolean).join(" ");
const inner = (
<span
ref={bodyRef}
className="relative grid h-full place-items-center overflow-hidden will-change-transform group-focus-visible/ll:ring-2 group-focus-visible/ll:ring-white/30"
style={{
minWidth: Math.round(H * 3.1),
padding: `0 ${Math.round(H * 0.8)}px`,
borderRadius: r,
background: "linear-gradient(180deg, #160b2e 0%, #0e0722 100%)",
boxShadow: "inset 0 1px 0 rgba(255,255,255,.06), 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35)",
}}
>
{/* the pool of light inside the glass */}
<span aria-hidden="true" className="pointer-events-none absolute inset-0 overflow-hidden" style={{ borderRadius: r }}>
{pool(0, 70)}
{ripple(0, 55)}
</span>
{/* the hairline edge: dim violet at rest, lit where the light passes */}
<span aria-hidden="true" className="pointer-events-none absolute inset-0 overflow-hidden" style={ring}>
<span className="absolute inset-0" style={{ background: "linear-gradient(200deg, rgba(150,110,255,.18), rgba(120,70,255,.42) 60%, rgba(150,110,255,.22))" }} />
{pool(1, 100)}
{ripple(1, 100)}
</span>
{/* a sheen across the top of the glass */}
<span aria-hidden="true" className="pointer-events-none absolute inset-x-0 top-0 h-1/2" style={{ borderRadius: `${r}px ${r}px 0 0`, background: "linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,0))" }} />
<span ref={textRef} className="relative whitespace-nowrap text-white will-change-transform" style={{ fontSize: Math.round(H * 0.33), fontWeight: 600, letterSpacing: "0.005em" }}>
{label}
</span>
</span>
);
return href ? (
<a ref={(el) => void (rootRef.current = el)} href={href} onClick={onClick} className={cls} style={{ height: H }}>
{inner}
</a>
) : (
<button ref={(el) => void (rootRef.current = el)} type="button" onClick={onClick} className={cls} style={{ height: H }}>
{inner}
</button>
);
}
export default LiquidLightButton;
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 "Button"default "Button"hrefstringRender a link.onClick() => voidClick handler.sizenumberHeight, px.default 56default 56fromstringThe light on the left.default "#8b2cf5"default "#8b2cf5"tostringThe light on the right.default "#2f55ff"default "#2f55ff"classNamestringExtra classes.