Typewriter
Type a phrase one character at a time, or type, erase, and cycle through several, with a blinking caret.
Overview
Typewriter reveals text one character at a time behind a caret. With one phrase it types once and stops, which suits a command line or a generated answer. With several, it types each one, holds it, erases it, and moves on to the next, a common way to show the range of a product in a heading.
The caret only blinks while the text is idle. A caret that blinks in the middle of typing looks like a stall.
Installation
Usage
import { Typewriter } from "@/components/animated/typewriter"
<h2>
Interfaces that feel{" "}
<Typewriter text={["calm.", "precise.", "honest."]} />
</h2>Type a single line once, after a short delay:
<Typewriter text="npx honestui add typewriter" startDelay={600} />Keep the line from reflowing as text is typed by giving the container room for the longest phrase, such as a min-w-[12ch] on the parent.
Accessibility
Screen readers receive every phrase once, joined with commas, from a visually hidden copy. The animated text and caret are hidden from them, so they never hear partial words. Don't put the only copy of important instructions in a cycling typewriter: sighted readers see each phrase for only a few seconds.
With reduced motion enabled, each phrase appears whole instead of being typed character by character, and the caret stops blinking.