Typewriter
Type a string one character at a time. Static for reduced motion.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
text required | string | – | The string to type. Screen readers get all of it at once. |
speed | number | 40 | Milliseconds per character. Default 40. |
delay | number | 0 | Milliseconds to wait before the first character. Default 0. |
cursor | boolean | true | Show 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
| Class | Stylesheet |
|---|---|
.typewriter-caret | typewriter.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.