Skip to content

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.json

Ship 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

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.

Props

PropTypeDefaultDescription
words (required)readonly string[]NoneThe words to cycle through, in order.
intervalnumber2.6Seconds each word stays.
direction"up" | "down""up"Which way words travel: "up" (in from below, default) or "down" (in from above).
align"center" | "end" | "start""start"Where a shorter word sits in the slot (the slot is as wide as the longest word).
pausedbooleanfalseStop cycling (e.g. from a pause button).
pauseOnHoverbooleantruePause while a mouse or pen rests on the words.
indexnumberNoneControlled index of the word shown.
defaultIndexnumber0Sets the index shown first when uncontrolled.
onIndexChange((index: number) => void)NoneCalled with the index of each new word.
labelstringNoneWhat screen readers hear instead of the list of words.
localesIntl.LocalesArgumentNoneLocale(s) for the default list label (Intl.ListFormat).
wordClassNamestringNoneClasses for each word (padding, gradient text). Put a highlight's padding here.
highlightClassNamestringNoneClasses for a highlight behind the current word (e.g. "rounded-sheen-md bg-sheen-accent-soft"). It morphs to fit each word.

Keyboard

KeysAction
TabNot focusable: this is text.

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

19 effects pages in all: browse them on All effects.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .