Text typed character by character, with an optional blinking cursor.
Installation
Usage
import {
TypingText,
TypingTextCursor,
} from '@animate-ui/react/primitives/texts/typing';
export function Hero() {
return (
<TypingText text={['Design', 'Build', 'Ship']} loop>
<TypingTextCursor />
</TypingText>
);
}Animation
- Characters are typed every
durationms (100). With several texts (orloop), a typed text holds forholdDelay, is erased at the same pace, and the next one is typed. - The text is written to the DOM directly: typing a character never re-renders React. Changing
durationorholdDelaymid-animation takes effect without restarting. - A loop pauses off screen and in a hidden tab; a single run only in a hidden tab. It resumes where it stopped.
- The cursor blinks (a 1s on/off loop) while it waits for
delayand once a text is typed, and stays solid while typing or erasing (it fades in over 0.3s as typing starts). It holds still off screen and in a hidden tab. - Under reduced motion, the text appears at once (the last text, or the first one with
loop) and the cursor doesn't blink. - Screen readers read every text once, never the partially typed ones.
API Reference
TypingText
| Prop | Type | Default |
|---|---|---|
text | string | string[] | - |
duration? | number | 100 |
delay? | number | 0 |
loop? | boolean | false |
holdDelay? | number | 1000 |
inView? | boolean | false |
inViewMargin? | string | '0px' |
inViewOnce? | boolean | true |
...props? | React.ComponentProps<'span'> | - |
TypingTextCursor
| Prop | Type | Default |
|---|---|---|
variants? | Variants | - |
...props? | Omit<HTMLMotionProps<'span'>, 'children'> | - |