Skip to content

Typewriter Effect for React

A typewriter effect for React that types each phrase with a human rhythm, holds it, deletes it and types the next. Use it as a typing animation for a hero line that cycles through a few phrases, such as I build design systems, fast websites and accessible apps, typed and deleted one after another.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/text-effects.json

Ask your assistant

Rotating phrases

Several phrases loop. It pauses while off screen, in a hidden tab, or under the pointer; paused, the caret holds still.

I build design systems. fast websites. accessible apps.

Files to copy

5 folders · 6 files · 4 packages
From theme/src/
  • components/text-effects/{text-utils.ts, typewriter.tsx}
  • hooks/{use-media-query.ts, use-preferences.ts}
  • motion/gate.ts
  • lib/cn.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/avatar/
  • components/glass-card/
  • components/spinner/
  • components/toast/
  • hooks/use-direction.ts
  • motion/{light-follower.ts, tokens.ts}
  • lib/{heading.ts, initials.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/avatar.json https://lokendra-builds.github.io/sheenui/r/glass-card.json https://lokendra-builds.github.io/sheenui/r/toast.json
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Terminal

Monospace, a block-ish caret, quicker keys. The reserved space keeps the card from jumping; in a flex row next to the prompt, a long command wraps inside its own column on narrow screens.

pnpm add @sheenui/theme pnpm dev --open git push origin main

Type once

A single phrase types once (loop is off by default for one phrase); the caret blinks a few times, then fades. onComplete fires at the end. The paragraph is already full height before the first letter.

Your workspace is ready. We imported 24 components, set up dark mode and turned on reduced-motion support.

Props

PropTypeDefaultDescription
words (required)string | readonly string[]NoneA phrase, or phrases to type one after another.
typeSpeednumber0.055Sets the seconds per typed character (on average).
deleteSpeednumber0.028Sets the seconds per deleted character.
holdnumber1.8Seconds a finished phrase stays before it is deleted.
startDelaynumber0.2Sets the number of seconds before the first character.
loopbooleantrue when there are several phrasesStart again after the last phrase.
cursorbooleantrueShow the caret. When typing ends (no loop), it blinks a few times and fades.
cursorClassNamestringNoneAdds extra classes to the caret (colour, width).
reserveSpacebooleantrueReserve the space of the longest phrase so nothing around it moves.
pausedbooleanfalseStop typing (e.g. from a pause button).
pauseOnHoverbooleantruePause while a mouse or pen rests on the text.
labelstringevery phrase, in orderSets what screen readers hear.
onComplete(() => void)NoneCalled once the last phrase is typed (when not looping).

Keyboard

KeysAction
TabNot focusable: this is text.

Accessibility

  • Screen readers get every phrase once, as plain text (override it with label); the typing itself is aria-hidden.
  • That copy is unselectable, so copying gets only what is on screen. It waits until it is on screen and pauses in a hidden tab or while the pointer rests on it: a pointer convenience, not a WCAG 2.2.2 mechanism, since keyboard and touch users cannot hover. A loop that runs longer than 5 s needs a visible pause button wired to paused. Under reduced motion it shows the first phrase, complete, with no caret.

When to use the typewriter effect

  • Use it for the rotating tagline in a portfolio or landing page hero, where one line has to say several things in turn: each phrase is typed out, held long enough to read, then deleted.
  • Use it for a terminal-style intro or a demo of a search box suggestion, where one phrase types once with the caret blinking and fading at the end.
  • Use typeSpeed, deleteSpeed, hold and startDelay to tune the rhythm; typing already has uneven keystrokes and a beat after punctuation, so it reads as human.
  • Skip it when only a single word changes inside a sentence, where WordRotate slides words in a fixed slot, or when the text matters for scanning; BlurIn is better for a one-time headline reveal.
  • Pair it with Button for the call to action below the line, ShimmerText for a supporting status line, and reserveSpace so the layout under the text never moves.

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 .