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.jsonAsk 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.
import { Typewriter } from "@/components/sheenui/text-effects/typewriter";
// Package build (after the first npm release, or a packed tarball): import { Typewriter } from "@sheenui/theme";
export function Example() {
return (
<p className="text-center text-3xl leading-tight font-semibold tracking-tight sm:text-4xl">
I build{" "}
<Typewriter
words={["design systems.", "fast websites.", "accessible apps."]}
className="text-sheen-accent"
/>
</p>
);
}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.tslib/cn.tsstyles/
- 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.tsmotion/{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
import { GlassCard } from "@/components/sheenui/glass-card/glass-card";
import { Typewriter } from "@/components/sheenui/text-effects/typewriter";
// Package build (after the first npm release, or a packed tarball): import { GlassCard, Typewriter } from "@sheenui/theme";
// This example also uses glass-card: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/glass-card.json
export function Example() {
return (
<GlassCard level={3} sheen={false} className="w-full max-w-md overflow-hidden">
{/* Window controls (decorative) */}
<div aria-hidden className="flex items-center gap-1.5 border-b border-sheen-border px-4 py-2.5">
<span className="size-2.5 rounded-full bg-sheen-danger" />
<span className="size-2.5 rounded-full bg-sheen-warning" />
<span className="size-2.5 rounded-full bg-sheen-success" />
</div>
<p className="flex gap-[1ch] p-5 font-sheen-mono text-sm">
<span aria-hidden className="text-sheen-fg-subtle">$</span>
<Typewriter
words={["pnpm add @sheenui/theme", "pnpm dev --open", "git push origin main"]}
typeSpeed={0.04}
hold={1.4}
cursorClassName="w-[0.6em] rounded-none bg-sheen-fg-muted"
className="min-w-0"
/>
</p>
</GlassCard>
);
}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.
import { Avatar } from "@/components/sheenui/avatar/avatar";
import { GlassCard } from "@/components/sheenui/glass-card/glass-card";
import { Typewriter } from "@/components/sheenui/text-effects/typewriter";
import { useToast } from "@/components/sheenui/toast/toast";
// Package build (after the first npm release, or a packed tarball): import { Avatar, GlassCard, Typewriter, useToast } from "@sheenui/theme";
// This example also uses avatar, glass-card, toast: 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
export function Example() {
const toast = useToast();
return (
<GlassCard className="flex w-full max-w-md gap-3 p-5">
<Avatar name="Sheen Assistant" size="sm" />
<p className="text-sm text-pretty">
<Typewriter
words="Your workspace is ready. We imported 24 components, set up dark mode and turned on reduced-motion support."
typeSpeed={0.025}
onComplete={() => toast.success("Setup complete")}
/>
</p>
</GlassCard>
);
}Props
Keyboard
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
Related pages
19 effects pages in all: browse them on All effects.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .