How it works
This typewriter effect types a line of text one character at a time behind a blinking caret, pauses, erases it, and types it again. It needs no JavaScript in the CSS version.
The trick is a width animation in ch units with a stepped timing function. The text sits in an element with overflow: hidden and white-space: nowrap, and a monospace font stack (ui-monospace, SF Mono, Menlo). In a monospace font every character is exactly 1ch wide, so the typing keyframe animates width from 0ch to the number of characters, and steps(N, end) with N equal to the text length makes it jump one whole character per step instead of sliding. It reaches full width at 70% and holds, and direction alternate types and then erases. The caret is a 0.12em border-right whose color toggles to transparent every 0.8s with steps(1, end).
Parameters: Text (up to 24 characters), Font size, Text color, Caret color and Duration. The step count and widths update automatically when you edit Text. About 0.1s per character feels like real typing, so 2.4s suits the default "Hello, world!".
The full text is in the DOM, so screen readers read it once without waiting for the animation. It does not work with proportional fonts or text that wraps. Under prefers-reduced-motion, show the full text and keep only the caret blink.
How do I make the typewriter text longer?
The editor allows up to 24 characters, which fits one line in most layouts. In the copied CSS you can use longer text by updating three numbers to the new character count: the width in ch on the element, the width at the 70% step, and the N in steps(N, end). Increase Duration proportionally so the typing speed stays the same.
Why does the typewriter effect need a monospace font?
The width animates in ch units, and 1ch equals the width of the zero character. Only in a monospace font is every character that wide, so each step reveals exactly one letter. With a proportional font, narrow letters like i and wide ones like W break the alignment and the caret ends up mid-letter.
Can I cycle through several words like a typing carousel?
Not with CSS alone, because the width and step count are fixed per string. Use the React version as a base: keep an array of words in state, change the text on each animation cycle, and the component recalculates widths. Keep the words to similar lengths so the layout does not jump.