Rotating Text for React
A rotating text animation for React: one slot in a sentence cycles through words, each sliding up through a clipped window.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/text-effects.jsonShip interfaces faster, calmer, clearer, and brighter
In a headline
highlightClassName draws a pill behind the current word: watch it morph between short and long words (transforms only, corners stay round). Padding goes in wordClassName so the pill and the word line up. Rest the pointer on it, or use the switch, to pause.
Built for designers, developers, founders, and everyone
import { useState } from "react";
import { Switch } from "@/components/sheenui/switch/switch";
import { WordRotate } from "@/components/sheenui/text-effects/word-rotate";
// Package build (after the first npm release, or a packed tarball): import { Switch, WordRotate } from "@sheenui/theme";
// This example also uses switch: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/switch.json
export function Example() {
const [paused, setPaused] = useState(false);
return (
<>
<Switch label="Pause" checked={paused} onCheckedChange={setPaused} />
<p className="text-center text-4xl leading-tight font-semibold tracking-tight text-balance sm:text-5xl">
Built for{" "}
<WordRotate
words={["designers", "developers", "founders", "everyone"]}
paused={paused}
className="text-sheen-accent"
wordClassName="px-3"
highlightClassName="rounded-sheen-md bg-sheen-accent-soft"
/>
</p>
</>
);
}Files to copy
5 folders · 9 files · 4 packages
- From
theme/src/ components/text-effects/{text-utils.ts, word-rotate.tsx}hooks/{use-controllable.ts, use-media-query.ts, use-preferences.ts}motion/{gate.ts, tokens.ts}lib/{cn.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/text-effects.jsonRegistry item: text-effects. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/switch/hooks/{use-direction.ts, use-latest.ts}lib/{field-control-shell.tsx, form.ts, motion-props.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/switch.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Inside running text
direction="down" brings words in from above; align="center" centers shorter words in the slot. A custom label gives screen readers a better sentence than the plain list.
Your dashboard, faster, clearer and calmer than ever.
import { WordRotate } from "@/components/sheenui/text-effects/word-rotate";
// Package build (after the first npm release, or a packed tarball): import { WordRotate } from "@sheenui/theme";
export function Example() {
return (
<p className="max-w-md text-center text-xl text-pretty sm:text-2xl">
Your dashboard,{" "}
<WordRotate
words={["faster", "clearer", "calmer"]}
direction="down"
align="center"
interval={2}
label="faster, clearer and calmer"
className="font-semibold text-sheen-accent"
/>{" "}
than ever.
</p>
);
}Props
Keyboard
Accessibility
- Screen readers get the words once, as plain text (override it with label); the rotating word is not re-announced every few seconds.
- Under reduced motion it stays on the current word.
When to use the word rotate effect
- Use it as a word rotate animation for one changing word in a headline, such as Design for designers, developers and everyone, where each word slides in from below as the last slides out the top. Use it as a text loop in React that cycles through a few phrases inside one headline.
- Use it for a feature tagline in a product page that lists audiences or use cases, with highlightClassName adding a pill behind the current word that morphs to fit each one. It is a quiet way to flip words in a headline without moving the layout under the text.
- Use controlled index with onIndexChange when other UI, like tabs or an illustration, should follow the word that is currently shown.
- Skip it when you need whole phrases typed out: Typewriter fits that, and a static sentence fits better when the words are important content, since users may not wait for every one.
- Pair it with BlurIn for the rest of the headline, Button for the action, and a Switch or your own button that sets paused so people can stop the cycling.
Frequently asked questions
Related pages
19 effects pages in all: browse them on All effects.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .