Components90 / 118
Split Word
A section intro where a big word slides apart into syllables and the whole collage of work rearranges around it: layout after layout, a different project grows to hero size while the syllables glide to new corners, then they close back into the word. Point at a project to bring it forward.
HeroHeroTypographyTypographyCollageCollageLayout animationLayout animationAnimation principlesAnimation principlesGSAPGSAP
Point at a projectClick it to open
Tweak
LIVELIVEContent
Word
Motion
0.75s
Usage
Follows your tweaks.
usage.tsx
import { SplitWord } from "@/components/inreact/split-word";
const work = [
{ src: "/work/lumo.jpg", title: "Lumo", href: "/work/lumo" },
{ src: "/work/verda.jpg", title: "Verda", href: "/work/verda", ratio: 1.12 },
// ... six projects in all
];
export function Intro() {
return <SplitWord word="Brands" parts={["Br","an","ds"]} items={work} height={720} />;
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/split-word.jsonOr copy the source
Install the dependencies, then save this as components/inreact/split-word.tsx.
terminal
npm install gsapcomponents/inreact/split-word.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef, useState } from "react";
/**
* Split Word: a section intro where a word breaks apart and the work rearranges around it.
*
* A big word ("Brands") sits closed among a scattered collage of six project
* images. It slides apart into its syllables ("Br", "an", "ds") and then the
* whole composition moves through a series of layouts: in each one a
* different project grows to hero size while the others drift to new spots
* and sizes, the middle syllable holds the centre and the outer two glide to
* new corners. Every move winds back a touch before it goes and overshoots a
* little as it lands (the type squashes as it settles), each element starting
* a beat after the last. After the last layout the syllables line up and
* close back into the word. Point at a project to bring its layout forward;
* click it to open it.
*
* <SplitWord word="Brands" parts={["Br", "an", "ds"]} items={[{ src: "/work/1.jpg", href: "/work/1" }, ...6]} />
*
* Six items fill the built-in layouts (extras are hidden). Only the word is set in type.
*/
export interface SplitWordItem {
src: string;
title?: string;
href?: string;
/** Width / height (default 1). */
ratio?: number;
}
export interface SplitWordProps {
word: string;
/** Exactly three parts that spell the word. Defaults to an even split. */
parts?: string[];
items: SplitWordItem[];
height?: number;
background?: string;
color?: string;
/** CSS font-family for the word (a neo-grotesk looks right). */
font?: string;
/** Seconds each layout holds before the next (0 = only on hover). */
hold?: 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));
const split3 = (w: string) => {
const a = Math.round(w.length / 3), b = Math.round((w.length * 2) / 3);
return [w.slice(0, a), w.slice(a, b), w.slice(b)];
};
// card: [centre x, centre y, width] as fractions (x of the width, y and width of the height)
type C = [number, number, number];
// syllable: [x, y, anchor] (-1 = left edge at x, 0 = centred, 1 = right edge at x); y = centre
type P = [number, number, number];
type Layout = { cards: C[]; parts: P[] | "closed" | "row" };
const REST: C[] = [[0.42, 0.115, 0.233], [0.1, 0.276, 0.165], [0.74, 0.28, 0.15], [0.643, 0.737, 0.183], [0.905, 0.905, 0.165], [0.19, 0.905, 0.125]];
const LAYOUTS: Layout[] = [
{ cards: REST, parts: "closed" },
{ cards: REST, parts: "row" },
{ cards: [[0.474, 0.283, 0.176], [0.126, 0.339, 0.22], [0.826, 0.19, 0.275], [0.524, 0.63, 0.1], [0.915, 0.754, 0.14], [0.246, 0.904, 0.144]], parts: [[0.012, 0.15, -1], [0.5, 0.5, 0], [0.99, 0.87, 1]] },
{ cards: [[0.47, 0.12, 0.135], [0.19, 0.27, 0.17], [0.676, 0.29, 0.165], [0.593, 0.727, 0.315], [0.915, 0.49, 0.165], [0.246, 0.755, 0.107]], parts: [[0.99, 0.065, 1], [0.5, 0.5, 0], [0.235, 0.935, 0]] },
{ cards: [[0.296, 0.09, 0.157], [0.204, 0.487, 0.12], [0.644, 0.122, 0.128], [0.613, 0.89, 0.167], [0.796, 0.463, 0.35], [0.152, 0.722, 0.107]], parts: [[0.99, 0.79, 1], [0.5, 0.5, 0], [0.012, 0.22, -1]] },
{ cards: [[0.244, 0.17, 0.14], [0.2, 0.478, 0.115], [0.644, 0.237, 0.243], [0.513, 0.7, 0.168], [0.88, 0.75, 0.18], [0.13, 0.72, 0.18]], parts: [[0.24, 0.935, 0], [0.5, 0.5, 0], [0.77, 0.065, 0]] },
{ cards: [[0.328, 0.157, 0.175], [0.163, 0.357, 0.135], [0.674, 0.276, 0.22], [0.58, 0.67, 0.18], [0.88, 0.86, 0.148], [0.143, 0.796, 0.165]], parts: [[0.012, 0.58, -1], [0.5, 0.5, 0], [0.99, 0.42, 1]] },
{ cards: REST, parts: "row" },
];
export function SplitWord({
word,
parts,
items,
height = 560,
background = "#ffffff",
color = "#0b0b0c",
font = "var(--font-grotesk), 'Inter Tight', 'Helvetica Neue', Helvetica, Arial, sans-serif",
hold = 0.75,
className,
}: SplitWordProps) {
const rootRef = useRef<HTMLDivElement>(null);
const cardRefs = useRef<(HTMLAnchorElement | null)[]>([]);
const partRefs = useRef<(HTMLSpanElement | null)[]>([]);
const [W, setW] = useState(0);
const segs = parts?.length === 3 ? parts : split3(word);
const shown = items.slice(0, 6);
const H = height;
useEffect(() => {
const el = rootRef.current;
if (!el) return;
const ro = new ResizeObserver(([e]) => setW(Math.round(e.contentRect.width)));
ro.observe(el);
return () => ro.disconnect();
}, []);
// the composition is designed nearly square: it keeps its proportions in a centred frame
// (never stretched thin across a wide section), sized by whichever side is tighter
const fw = Math.min(W || H, H * 1.32);
const fx = ((W || fw) - fw) / 2;
const unit = Math.min(H, fw);
const fsWord = Math.round(unit * 0.135);
const base = unit * 0.36; // cards are drawn at the hero size and scaled down: always crisp
useEffect(() => {
const root = rootRef.current;
if (!root || !W) return;
const still = reduced();
const m = shown.length;
const cards = cardRefs.current.slice(0, m);
const ps = partRefs.current.slice(0, 3);
const widths = [0, 0, 0];
const measure = () => ps.forEach((el, i) => (widths[i] = el ? el.offsetWidth : fsWord));
measure();
const pad = unit * 0.02; // syllables never touch the edges
const cardTo = (i: number, c: C) => {
const r = shown[i].ratio ?? 1;
const bw = base, bh = base / r;
return { x: fx + c[0] * fw - bw / 2, y: c[1] * H - bh / 2, scale: (c[2] * unit) / bw };
};
const partsTo = (L: Layout["parts"]) => {
const lh = fsWord;
const cy = H * 0.5 - lh * 0.55;
if (L === "closed") {
const total = widths[0] + widths[1] + widths[2];
let x = fx + (fw - total) / 2;
return widths.map((w) => {
const o = { x, y: cy };
x += w;
return o;
});
}
if (L === "row") {
// spread along a row: first at the left edge, middle centred, last at the right edge
return [
{ x: fx + pad, y: cy },
{ x: fx + fw * 0.5 - widths[1] / 2, y: cy },
{ x: fx + fw - pad - widths[2], y: cy },
];
}
return L.map(([x, y, a], i) => ({
x: clamp(fx + pad, fx + fw - pad - widths[i], fx + x * fw - (a === -1 ? 0 : a === 0 ? widths[i] / 2 : widths[i])),
y: clamp(pad * 0.5, H - lh * 1.12, y * H - lh * 0.55),
}));
};
// place everything at the opening layout
const L0 = LAYOUTS[0];
cards.forEach((el, i) => el && gsap.set(el, { ...cardTo(i, L0.cards[i]), transformOrigin: "50% 50%" }));
partsTo(L0.parts).forEach((p, i) => ps[i] && gsap.set(ps[i], { ...p, transformOrigin: "50% 80%" }));
let cur = 0;
const go = (k: number) => {
cur = k;
const L = LAYOUTS[k];
const dur = still ? 0 : 0.85;
cards.forEach((el, i) => {
if (!el) return;
const t = cardTo(i, L.cards[i]);
// winds back a touch, then overshoots a little as it lands; each card a beat after the last
gsap.to(el, { x: t.x, y: t.y, duration: dur, ease: "power3.inOut", delay: still ? 0 : i * 0.025, overwrite: "auto" });
gsap.to(el, { scale: t.scale, duration: dur, ease: "back.inOut(1.25)", delay: still ? 0 : i * 0.025, overwrite: "auto" });
el.style.zIndex = String(Math.round(L.cards[i][2] * 100));
});
partsTo(L.parts).forEach((p, i) => {
const el = ps[i];
if (!el) return;
gsap.to(el, { x: p.x, y: p.y, duration: dur, ease: "back.inOut(1.1)", delay: still ? 0 : 0.05 + i * 0.04, overwrite: "auto" });
if (!still)
// a small stretch on the way, a squash as it settles
gsap
.timeline({ delay: 0.05 + i * 0.04 })
.to(el, { scaleX: 1.06, scaleY: 0.95, duration: dur * 0.45, ease: "sine.inOut" })
.to(el, { scaleX: 0.97, scaleY: 1.04, duration: dur * 0.3, ease: "sine.inOut" })
.to(el, { scaleX: 1, scaleY: 1, duration: 0.35, ease: "elastic.out(1, 0.5)" });
});
};
// the loop: closed → row → layouts → row → closed
let timer = 0, hovering = false, ready = false;
const holdMs = (k: number) => (k === 0 ? 1100 : k === 1 || k === LAYOUTS.length - 1 ? 450 : hold * 1000) + 850;
const schedule = () => {
window.clearTimeout(timer);
if (still || hold <= 0 || !ready) return;
timer = window.setTimeout(() => {
if (hovering) return schedule();
go((cur + 1) % LAYOUTS.length);
schedule();
}, holdMs(cur));
};
// decode every photo before anything moves, so the first transitions never stutter
let alive = true;
const imgs = cards.map((el) => el?.querySelector("img")).filter(Boolean) as HTMLImageElement[];
Promise.all(imgs.map((im) => (im.decode ? im.decode().catch(() => undefined) : Promise.resolve()))).then(() => {
if (!alive) return;
ready = true;
schedule();
});
// the layout where each project is the hero
const heroOf = shown.map((_, i) => {
let best = 2, bw = -1;
LAYOUTS.forEach((L, k) => {
if (k < 2 || k === LAYOUTS.length - 1) return;
if (L.cards[i][2] > bw) (bw = L.cards[i][2]), (best = k);
});
return best;
});
let intent = 0;
const onEnter = (i: number) => () => {
hovering = true;
window.clearTimeout(intent);
// a short dwell first, so sweeping across the collage doesn't make it jump
intent = window.setTimeout(() => {
const L = LAYOUTS[cur];
const big = Math.max(...L.cards.map((c) => c[2]));
if (L.cards[i][2] < big - 1e-6 || typeof L.parts === "string") go(heroOf[i]);
}, 140);
};
const onLeave = () => {
hovering = false;
window.clearTimeout(intent);
schedule();
};
const offs = cards.map((el, i) => {
if (!el) return () => {};
const enter = onEnter(i);
el.addEventListener("pointerenter", enter);
el.addEventListener("pointerleave", onLeave);
return () => {
el.removeEventListener("pointerenter", enter);
el.removeEventListener("pointerleave", onLeave);
};
});
const onKey = (e: KeyboardEvent) => {
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
e.preventDefault();
go((cur + (e.key === "ArrowRight" ? 1 : LAYOUTS.length - 1)) % LAYOUTS.length);
schedule();
}
};
root.addEventListener("keydown", onKey);
// web fonts can arrive after the first layout: measure again and settle the word with real widths
document.fonts?.ready.then(() => {
if (!alive) return;
measure();
partsTo(LAYOUTS[cur].parts).forEach((p, i) => ps[i] && gsap.set(ps[i], p));
});
return () => {
alive = false;
window.clearTimeout(timer);
window.clearTimeout(intent);
offs.forEach((f) => f());
root.removeEventListener("keydown", onKey);
gsap.killTweensOf([...cards, ...ps]);
};
}, [W, H, fw, fx, unit, base, fsWord, hold, shown.length, segs.join("|")]); // eslint-disable-line react-hooks/exhaustive-deps
return (
<div
ref={rootRef}
tabIndex={0}
role="region"
aria-label={word}
className={["relative w-full overflow-hidden outline-none select-none", className].filter(Boolean).join(" ")}
style={{ height: H, background, color, fontFamily: font }}
>
{/* the work */}
{shown.map((it, i) => (
<a
key={i}
ref={(el) => void (cardRefs.current[i] = el)}
href={it.href ?? undefined}
aria-label={it.title ?? `Project ${i + 1}`}
onClick={(e) => !it.href && e.preventDefault()}
className="absolute top-0 left-0 block overflow-hidden will-change-transform"
style={{ width: base, height: base / (it.ratio ?? 1), cursor: "pointer", backfaceVisibility: "hidden", contain: "layout paint" }}
>
<img src={it.src} alt="" width={Math.round(base)} height={Math.round(base / (it.ratio ?? 1))} draggable={false} decoding="async" className="pointer-events-none h-full w-full object-cover" />
</a>
))}
{/* the word, in three pieces */}
<h2 className="sr-only">{word}</h2>
{segs.map((s, i) => (
<span
key={i}
ref={(el) => void (partRefs.current[i] = el)}
aria-hidden="true"
className="pointer-events-none absolute top-0 left-0 whitespace-pre will-change-transform"
style={{ fontSize: fsWord, lineHeight: 1, fontWeight: 500, letterSpacing: "-0.035em", zIndex: 60 }}
>
{s}
</span>
))}
</div>
);
}
export default SplitWord;
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
9 propswordstringThe word.partsstring[]Three syllables that spell the word (defaults to an even split).items{ src: string; title?: string; href?: string; ratio?: number }[]Six projects (crisp images, at least 900px).heightnumberHeight, px.default 560default 560fontstringFont for the word (a neo-grotesk looks right).holdnumberSeconds each layout holds (0 = only on hover).default 0.75default 0.75backgroundstringBackground.default "#ffffff"default "#ffffff"colorstringText colour.default "#0b0b0c"default "#0b0b0c"classNamestringExtra classes.