Components

Typewriter

A typewriter text effect for React and Tailwind CSS that types and deletes a list of phrases with a blinking caret. It reserves the space of its longest phrase so nothing shifts, pauses off-screen, and keeps every phrase in the DOM for search engines and screen readers.

  • SEO-friendly real text
  • No layout shift
  • Bar, block & underscore carets
  • Pauses off-screen
  • prefers-reduced-motion

Built for landing pages, dashboards, design systems, side projects

Installation

$ npx shadcn@latest add https://duskui.com/r/typewriter.json

Usage

hero.tsx
import { Typewriter } from "@/components/dusk/text/typewriter"

export function Hero() {
  return (
    <h1 className="text-5xl font-bold">
      Ship{" "}
      <Typewriter
        phrases={["faster", "safer", "together"]}
        className="text-muted-foreground"
      />
    </h1>
  )
}

Examples

Caret styles

cursor picks a bar, block or underscore caret (or none). Color it with cursorClassName. The caret stays solid while typing and blinks while idle.

bar › npm run build, npm run dev

block › git push, git pull --rebase

underscore › ssh dusk@prod, exit

Play once

With loop={false} it stops on the last phrase. typeFirst types the first phrase from an empty line instead of starting with it already written.

$ Compiling…, Optimizing assets…, Deployed to production ✓

Wrapping without layout shift

Every phrase is stacked invisibly in the same grid cell, so the element is always as wide and tall as the longest one. Long phrases wrap naturally and the content below never jumps.

Reserve space for the longest phrase, So nothing below it jumps, Even when lines wrap on small screens

This paragraph never moves: the heading is always as tall as its longest phrase.

API Reference

Also accepts any HTML attribute for the rendered element.

PropTypeDefaultDescription
phrasesstring[]—Phrases to type, in order. Inline arrays are fine; it restarts only when the content changes.
as"span" | "p" | "div" | "strong" | "h1" … "h6""span"Element to render. span sits inline in a sentence.
typeSpeednumber70Milliseconds per typed character, slightly varied so it feels human.
deleteSpeednumber38Milliseconds per deleted character.
pausenumber1800How long a finished phrase stays before it is deleted, in ms.
startDelaynumber400Delay before the first keystroke, in ms.
loopbooleantrueCycle forever. When false it stops on the last phrase.
typeFirstbooleanfalseType the first phrase from an empty line. By default it is already written (and server-rendered).
cursor"bar" | "block" | "underscore" | "none""bar"Caret style.
cursorClassNamestring—Extra classes for the caret, e.g. a background color.
startOnViewbooleantrueWait until the text scrolls into view before typing.
labelstringphrases joined with ", "Text for screen readers and search engines.

Accessibility

  • All phrases are in the DOM as visually hidden text (override with label), so screen readers hear the full list once instead of a stream of keystrokes, and crawlers index every phrase.
  • The animated copy is aria-hidden; the hidden size-reserving copies are invisible and unselectable.
  • The element reserves the size of its longest phrase, so it causes no layout shift (CLS) while typing.
  • Typing pauses while the element is off-screen or the tab is hidden.
  • With prefers-reduced-motion no typing happens: a finished phrase is shown and the caret stops blinking.