Overview
The typewriter effect reveals text one character (or line) at a time. The width-reveal approach animates a wrapper’s width from 0 to its content width with steps(N, end) timing so each step lands on a character boundary. A separate caret element blinks independently so its rhythm does not couple to the typing cadence.
When to use it
Reach for typewriter reveals on hero quotes, terminal-style product surfaces, single-line CTAs that want a dramatic entrance. Skip it for long paragraphs — users will scan ahead of the animation and the effect becomes friction. Skip it for content that screen readers need to announce immediately; the live region behavior of partially-revealed text is inconsistent across AT.
How it works
Wrap the text in a fixed-width container with overflow: hidden; the inner text node has white-space: nowrap so it does not break across lines. Animate the container’s width from 0 to a value matching the full text width (typically 20ch or measured at build time). Use animation-timing-function: steps(N, end) where N is the character count, so the width increments by one character-width per step instead of sliding smoothly. The caret is a separate ::after pseudo with its own blink keyframe so its rhythm stays independent.
Production gotchas
steps(N, end) requires N to match the visible character count; miscount and the final character pops in mid-animation. For proportional fonts, ch units approximate but do not match real character widths — either use a monospace font or measure the text width with JS at mount. The container’s width animation triggers reflow on every step — for long strings this becomes noticeable; switch to a clip-path approach above ~40 characters. Animating max-width instead of width avoids one edge case where the container collapses below content width.
Accessibility
The full text is in the DOM throughout the animation, just clipped visually — screen readers announce the entire string immediately, not character-by-character. Under prefers-reduced-motion: reduce skip the width animation and reveal the text instantly; the caret blink is decorative and can stay or pause depending on preference.
References
Implementation depth
A width-based typewriter works when the text is measured in predictable units. max-content and ch units can produce a clean reveal for monospaced or controlled strings, while proportional fonts need more testing.
The caret should not be the only sign of state. Pause or remove blink under reduced motion, keep the final text selectable, and avoid long reveals that make users wait for essential copy.