Text
Rotating Word
One sentence, one word that keeps changing.
"use client";
import { useRef } from "react";
import gsap from "gsap";
import { useGSAP } from "@gsap/react";
gsap.registerPlugin(useGSAP);
export type RotatingWordProps = {
/** Text before the word that changes. */
prefix?: string;
/** Words that take turns in the slot. */
words?: string[];
/** Text after the word that changes. */
suffix?: string;
/** Color of the changing word. */
accent?: string;
/** Replay forever. */
loop?: boolean;
className?: string;
};
export default function RotatingWord({
prefix = "Build your next",
words = ["landing page", "dashboard", "checkout", "onboarding"],
suffix = "in minutes.",
accent = "#1f5bff",
loop = true,
className = "",
}: RotatingWordProps) {
const root = useRef<HTMLDivElement>(null);
useGSAP(
() => {
const q = gsap.utils.selector(root);
const track = q("[data-track]")[0];
const slot = q("[data-slot]")[0] as HTMLElement;
const n = words.length;
// Largura fixa: o espaço tem a largura da palavra mais longa (em em, para seguir o tamanho da
// fonte), assim a frase não muda de linha quando a palavra troca.
const size = parseFloat(getComputedStyle(slot).fontSize) || 16;
const widest = Math.max(...(q("[data-word]") as HTMLElement[]).map((el) => el.offsetWidth));
slot.style.width = `${widest / size}em`;
const tl = gsap.timeline({ repeat: loop ? -1 : 0 });
tl.set(track, { yPercent: 0, filter: "blur(0px)" });
for (let i = 1; i <= n; i++) {
const at = i * 1.3;
tl.to(track, { yPercent: -(100 / (n + 1)) * i, duration: 0.55, ease: "expo.inOut" }, at);
// Desfoque de movimento só no meio da troca.
tl.to(track, { filter: "blur(3px)", duration: 0.22, ease: "power2.in" }, at + 0.05);
tl.to(track, { filter: "blur(0px)", duration: 0.28, ease: "power2.out" }, at + 0.27);
}
tl.set(track, { yPercent: 0 }, n * 1.3 + 0.5).to({}, { duration: 1.2 });
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) tl.progress(1).pause();
},
{ scope: root, dependencies: [loop, words.join("|")] },
);
return (
<div
ref={root}
className={`text-[clamp(1.75rem,5vw,2.75rem)] leading-[1.15] font-bold tracking-tight ${className}`}
>
<p>
{prefix}{" "}
<span data-slot className="inline-block h-[1.15em] overflow-hidden align-bottom" style={{ color: accent }}>
<span data-track className="block">
{[...words, words[0]].map((word, i) => (
<span key={i} data-word className="block h-[1.15em] w-max leading-[1.15em] whitespace-nowrap">
{word}
</span>
))}
</span>
</span>
{/* Linha própria: com o espaço de largura fixa, a sobra fica no fim da linha e não vira um vão no meio da frase. */}
<span className="block">{suffix}</span>
</p>
</div>
);
}
Paste this into Claude Code inside your project. It installs the skills your agent needs, asks for your texts and colors, and recreates this animation in your stack.
SkillsGSAP skillsHyperFrames · optional, for video
Claude Code
Recreate the "Rotating Word" animated component from Motionshelf (https://motionshelf-pi.vercel.app) in my current project, adapted to my brand. Answer me in the language I write to you in. Work in this order: 1. Tools: Check whether the official GSAP skills are installed (gsap-core, gsap-timeline, gsap-react). If they are not, ask me and then run `npx skills add https://github.com/greensock/gsap-skills` (choose Claude Code). If they do not show up in this session yet, read the SKILL.md files the installer created for gsap-timeline and gsap-react before writing code. 2. Project: Look at my project: framework (Next.js, Vite, plain HTML…), TypeScript or JavaScript, Tailwind or plain CSS. Build it as one component that fits this stack. In React use gsap and @gsap/react; in plain HTML use GSAP from npm or a CDN. 3. Ask me before coding: Ask me these in a single message, showing the example values as defaults: - the text before the word, the words that rotate and the text after - the accent color of the word - the language of the texts 4. The animation What it looks like: One sentence where a single word keeps changing, for example "Build your next / landing page / in minutes." The changing word is in the accent color. Step by step: - The changing words are stacked in a vertical track inside a slot one line tall with overflow hidden; the first word is repeated at the end so the loop is seamless. - Every 1.3 s the track moves up one word (yPercent step, 0.55 s, expo.inOut) with a short blur (3 px) only in the middle of the move. - After the repeated first word, the track jumps back to the start without animation and the loop continues. Rules: - Use one GSAP timeline that loops forever with a short pause between runs (repeat: -1). If the step by step gives the pause, use that value; otherwise repeatDelay about 1.4 s. - Set every starting state with set() at the start of the timeline, never with from(): on the second loop from() starts from the wrong place. - Elements that appear later and would push the layout (new chat bubbles, new rows) stay display:none until their turn; elements that already have their place in the layout (a subtitle, a button) start hidden with autoAlpha 0, so nothing jumps. - If there is a cursor or pointer, it aims at the measured center of its target (getBoundingClientRect), never at fixed pixel coordinates; if the component is scaled, divide by the scale. - Blur only in the middle of a movement and always end at blur(0). - With prefers-reduced-motion, jump to the final frame and stop (tl.progress(1).pause()). - In React, use useGSAP from @gsap/react with a scope ref, so the timeline is cleaned up on unmount. - All example content stays generic (no real brands, logos or people). - Put the text after the word on its own line, so a short word never leaves a gap and the sentence never reflows when the word changes. - The slot is as wide as the longest word, measured once. 5. Check: Run it and watch the first and the third loop (they must look the same). Check it at 390 px wide with no sideways scroll, with reduced motion turned on, and with a clean console. Tell me what you checked. 6. Video (optional): If I also want this as an MP4 (ads, stories, WhatsApp status), install the HyperFrames plugin with `claude plugin marketplace add heygen-com/hyperframes` and `claude plugin install hyperframes@hyperframes`, then use /hyperframes:hyperframes to render the same animation in 9:16, 1:1 or 16:9. Rendering needs FFmpeg installed, or render with --docker (downloads about 3.3 GB the first time). Ask me before installing. Shortcut: If I only want the ready-made component instead, it installs with `npx shadcn@latest add https://motionshelf-pi.vercel.app/r/rotating-word.json`.
Other agentsUsing Cursor, Codex, Gemini CLI or another agent? This version tells it to find its own way to load the same skills before it starts.
Other agents
Recreate the "Rotating Word" animated component from Motionshelf (https://motionshelf-pi.vercel.app) in my current project, adapted to my brand. Answer me in the language I write to you in. Work in this order: 1. Tools: These instructions were written for Claude Code, which uses "skills" (folders with a SKILL.md that teach it a technique). First find out how you load skills, rules or instructions, and get the same knowledge: (a) if your agent is supported by the skills installer, ask me and run `npx skills add https://github.com/greensock/gsap-skills --agent <your-agent>` (for example codex, opencode, antigravity); (b) otherwise copy the skill folders from https://github.com/greensock/gsap-skills into your skills or rules directory (in Cursor: Settings → Rules → Remote Rule (GitHub) → greensock/gsap-skills); (c) if you cannot load skills at all, open the SKILL.md files in https://github.com/greensock/gsap-skills and read them as instructions before coding. Tell me which path you used. 2. Project: Look at my project: framework (Next.js, Vite, plain HTML…), TypeScript or JavaScript, Tailwind or plain CSS. Build it as one component that fits this stack. In React use gsap and @gsap/react; in plain HTML use GSAP from npm or a CDN. 3. Ask me before coding: Ask me these in a single message, showing the example values as defaults: - the text before the word, the words that rotate and the text after - the accent color of the word - the language of the texts 4. The animation What it looks like: One sentence where a single word keeps changing, for example "Build your next / landing page / in minutes." The changing word is in the accent color. Step by step: - The changing words are stacked in a vertical track inside a slot one line tall with overflow hidden; the first word is repeated at the end so the loop is seamless. - Every 1.3 s the track moves up one word (yPercent step, 0.55 s, expo.inOut) with a short blur (3 px) only in the middle of the move. - After the repeated first word, the track jumps back to the start without animation and the loop continues. Rules: - Use one GSAP timeline that loops forever with a short pause between runs (repeat: -1). If the step by step gives the pause, use that value; otherwise repeatDelay about 1.4 s. - Set every starting state with set() at the start of the timeline, never with from(): on the second loop from() starts from the wrong place. - Elements that appear later and would push the layout (new chat bubbles, new rows) stay display:none until their turn; elements that already have their place in the layout (a subtitle, a button) start hidden with autoAlpha 0, so nothing jumps. - If there is a cursor or pointer, it aims at the measured center of its target (getBoundingClientRect), never at fixed pixel coordinates; if the component is scaled, divide by the scale. - Blur only in the middle of a movement and always end at blur(0). - With prefers-reduced-motion, jump to the final frame and stop (tl.progress(1).pause()). - In React, use useGSAP from @gsap/react with a scope ref, so the timeline is cleaned up on unmount. - All example content stays generic (no real brands, logos or people). - Put the text after the word on its own line, so a short word never leaves a gap and the sentence never reflows when the word changes. - The slot is as wide as the longest word, measured once. 5. Check: Run it and watch the first and the third loop (they must look the same). Check it at 390 px wide with no sideways scroll, with reduced motion turned on, and with a clean console. Tell me what you checked. 6. Video (optional): If I also want this as an MP4 (ads, stories, WhatsApp status), install the HyperFrames skills with `npx skills add heygen-com/hyperframes` (choose your agent) and render the same animation in 9:16, 1:1 or 16:9. Rendering needs FFmpeg installed, or render with --docker (downloads about 3.3 GB the first time). Ask me before installing. Shortcut: If I only want the ready-made component instead, it installs with `npx shadcn@latest add https://motionshelf-pi.vercel.app/r/rotating-word.json`.
Install
npx shadcn@latest add https://motionshelf-pi.vercel.app/r/rotating-word.jsonCopies the file into your project. Requires React 19, Tailwind CSS v4 and GSAP (installed as a dependency).
Props
| Name | Type | Default | Description |
|---|---|---|---|
| prefix | string | "Build your next" | Text before the word that changes. |
| words | string[] | ["landing page", "dashboard", "checkout", "onboarding"] | Words that take turns in the slot. |
| suffix | string | "in minutes." | Text after the word that changes. |
| accent | string | "#1f5bff" | Color of the changing word. |
| loop | boolean | true | Replay forever with a pause between runs. |
| className | string | "" | Extra classes for the outer element. |
Dependencies
- gsap
- @gsap/react