Components

Typewriter

Text that types itself in the typewriter face, with an inked caret. Keys land at uneven speeds and hold at commas and periods; several phrases can go one under the other or be typed, held and backspaced in turn.

Install

terminal
npx shadcn@latest add @wobko/typewriter

First time here? Add the registry to components.json first. How to install

Examples

Default

It waits until it is on screen, then types at an uneven pace, holding at the comma and the period.

A rotating word

mode="cycle" types a word, holds it, backspaces it and moves on; loop keeps it going. A block caret, and the sentence still reads once to a screen reader.

Printing a receipt

A real use: an order confirmation types itself onto a receipt, and onDone brings in the button. `reserve` holds the height of the finished receipt, so the paper does not grow (or move, in a centered stage) as it prints. Print another remounts it with a new key.

API reference

Typewriter

An inline element. The animation is aria-hidden; the whole text sits in the accessibility tree once, in a polite live region that only changes when you change `text`. Without JavaScript, or with reduced motion, the finished text is simply there.

PropTypeDefaultDescription
textstring | string[]-What to type. An array is several phrases.
mode"lines" | "cycle""lines"lines: each phrase on its own line. cycle: type a phrase, hold it, backspace it, type the next (a loop or a rotating word).
speednumber22Characters per second, as an average: every key has its own delay.
delay / pausenumber300 / 1400ms before it starts, and ms to hold a finished phrase.
loopbooleanfalseStart again from an empty page when done. The live region is switched off while it loops, so it is never read twice.
cursor"bar" | "block" | "underscore" | false"bar"The caret, drawn with the pen. Solid while typing, blinking when it rests (not blinking with reduced motion).
reservebooleanfalseKeep the room of the finished text (the longest phrase of a cycle) from the first frame, so nothing around it moves while it types. The element becomes an `inline-block` (or the `display` your className sets) with an invisible copy of the finished text in flow and the typed text laid over it. Off, it is an inline element that grows as it types and can sit inside a sentence.
startOnViewbooleantrueWait until it is at least 40 % on screen.
onDone() => void-Called when the last character is on the page (never when looping).
seedstring | number-Pins the caret's hand and the jitter of the words.

Accessibility

  • Screen readers get the whole text once, from a visually hidden polite live region; they never hear it letter by letter. The typed copy is aria-hidden. Changing `text` is announced once.
  • In cycle mode and when looping the live region is off, so a rotating word is not announced on every turn; the phrases are all available as one sentence in reading order.
  • Reduced motion (the OS setting, data-motion="reduced", or an InkProvider with motion="reduced"): no typing, no blinking; the finished text (the last phrase of a cycle) is shown.
  • Without JavaScript the server has already sent the whole text in the page.
  • Layout: by default the element grows as it types, so anything below it moves. Pass `reserve` to hold the room of the finished text from the first frame (an invisible copy in flow, aria-hidden, that no one can select), or give a block of several lines a `min-h-*`. It is made for a headline or a few short lines: every key press re-renders the words typed so far, so do not feed it pages of text.
  • One key press is one character as a person sees it: an emoji, a flag or a letter with its accent is typed and erased whole, never in halves.
  • Words sit up to a pixel off the baseline and a shade lighter, as plain inline text (a word with a layer of its own was cut at its advance by WebKit, which clipped the tail of a hand font's last glyph); calm density and reduced motion turn the jitter off through --ll-jitter-k.

Source

The files the CLI copies into your project.

Loading the source