Playground

Typewriter

Type a string one character at a time. Static for reduced motion.

  • Built on native elements
  • Screen readers get the full text at once from an sr-only copy; the typed characters are aria-hidden.
  • With prefers-reduced-motion the full text shows immediately and the caret does not blink.
  • Styles in one file: typewriter.css

Import

import '@monoline/css';
import {Typewriter} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add typewriter

Usage

import {Typewriter} from '@monoline/react';

<p style={{fontFamily: 'var(--font-display)', fontSize: 'var(--display-sm)'}}>
  <Typewriter text="Small parts, drawn with thin lines." />
</p>

Examples

Default

Slow, no caret

Props

TypewriterProps

PropTypeDefaultDescription
text requiredstring–The string to type. Screen readers get all of it at once.
speednumber40Milliseconds per character. Default 40.
delaynumber0Milliseconds to wait before the first character. Default 0.
cursorbooleantrueShow a blinking caret. Default true.
onComplete(() => void)–Called once the last character is shown (also straight away for reduced motion).

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

This component sets no state attributes.

CSS classes

ClassStylesheet
.typewriter-carettypewriter.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.typewriter-caret {
  border-color: var(--accent);
}

Accessibility

  • Screen readers get the full text at once from an sr-only copy; the typed characters are aria-hidden.
  • With prefers-reduced-motion the full text shows immediately and the caret does not blink.