Skip to content
English
Typewriter comes with Pro. Its preview shows once you unlock it.

How it works

The frame never changes while typing: every segment renders an invisible ghost in one grid cell, so the cell matches the longest one, and the typing layer holds the full text with the untyped part hidden, so every character starts in its final place. The cursor takes no width. Text is split by grapheme, so emoji and flags are never typed in halves. One timer per step; it stops in the background or when paused.

Use it for

  • Rotating search box hints such as “Try: wireless headphones”, showing what can be searched.
  • A single tagline on a home or campaign page that should feel alive.
  • Opening lines or example questions for a support bot or AI assistant.

Look elsewhere when

  • Body text, instructions or errors people must read at once: waiting for characters slows reading.
  • Real streaming output from a model: just append the text as it arrives; no need to fake it.
  • Several on one screen: the cursor and moving text are eye-catching, so keep one.
  • Swapping a single word inside a sentence: a word rotator is cleaner.

Usage

import { useRef } from 'react'
import { Typewriter } from './Typewriter.jsx'

// Several segments in rotation: a search box hint
export function SearchHint() {
  return (
    <span>
      Try:{' '}
      <Typewriter text={['Wireless headphones', 'Trail running shoes', 'Coffee starter kit']} speed={70} pause={1600} />
    </span>
  )
}

// One segment: types, stops, and can be replayed
export function Slogan() {
  const ref = useRef(null)
  return (
    <>
      <Typewriter ref={ref} as="h1" text="Good things, found fast" startDelay={300} hideCursorOnDone onDone={() => console.log('done')} />
      <button onClick={() => ref.current?.restart()}>Replay</button>
    </>
  )
}

Props

PropTypeDefaultWhat it does
textstring | string[]—Text to type, may contain \n. An array types a segment, pauses, deletes it and types the next. Only the content is compared, so a new array literal on every render does not restart it.
speednumber70Typing speed: interval per character in ms.
deleteSpeednumber35Deleting speed: interval per character in ms.
pausenumber1600How long to wait after a segment is typed before deleting it, in ms.
loopbooleantrueWhether several segments loop; false stops after the last one. A single segment always stops when typed.
cursorbooleantrueShows the cursor; set its colour with the CSS variable --ds-typewriter-cursor (default: primary colour).
hideCursorOnDonebooleanfalseFades the cursor out once everything is typed and stopped (it keeps blinking by default).
startDelaynumber0Wait before typing the first character, in ms.
naturalbooleantrueVaries each interval between 0.6 and 1.4 times speed so it feels human; false is steady.
labelstringthe text; several segments joined with “, ”Text read by screen readers. By default one segment is read as is and several are joined with a comma (an enumeration comma for CJK text).
onDone() => void—Called when everything is typed and stopped (a single segment, or the last one when loop is false). Not called while looping.
pausedbooleanfalsePauses on the current character and continues from there on resume. It also pauses by itself when the page goes to the background.
as'span' | 'p' | 'div' | 'h1' | 'h2' | 'h3' | 'h4''span'The tag to render. span is inline; the others are block-level.
refRef<{ restart }>—Exposes restart(), which types everything again from the start.
...restHTMLAttributes<HTMLElement>—Other attributes go to the root element, such as className and style.

Accessibility

  • Screen readers get one complete hidden text (several segments joined); the changing visible layer is aria-hidden, so there is no character-by-character announcement and no aria-live.
  • The hidden text and ghosts cannot be selected, so copying gets only what is visible.
  • Real h1 / h2 / p tags are kept, so heading levels still work.
  • With reduced motion there is no typing and no cursor: a single segment shows in full and calls onDone, several fade in whole at the pause plus 1.2 seconds.
  • The frame size is fixed, so changing text never pushes surrounding content, which helps magnifier and low-vision users.

Motion

Typing takes 70ms per character (varying 0.6 to 1.4 times); pause 1600ms; deleting 35ms per character; the cursor blinks on a 1.1s loop, solid while typing or deleting. With reduced motion a segment fades in over 240ms.

Add it to your project

Pro members copy a prompt and their coding agent installs the source, the same way as the free components.

Typewriter.jsxtypewriter.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Text motion
Morphing text comes with Pro. Its preview shows once you unlock it.