Typing Animation
The TypingAnimation component reveals text one character at a time, simulating real-time text generation. It’s commonly used for AI assistant responses and chat interfaces. Since it extends the Text component, it accepts all of Text’s styling props.
Playground
Installation
import { TypingAnimation } from "@harnessio/ui/components";
// Basic usage<TypingAnimation text="Hello, world!" />
// With custom speed and delay<TypingAnimation text="Welcome to the chat!" typingSpeed={30} delay={500} />
// With a completion callback<TypingAnimation text="Processing complete." onComplete={() => console.log("Typing finished!")}/>
// With Text styling<TypingAnimation text="Important message" variant="heading-small" color="foreground-1" />;Behavior
- Plays once. The typing effect runs a single time. After it completes, later re-renders of the same instance show the full text immediately.
- Changing
text. Iftextchanges before the first animation finishes, it resets and replays with the new value. Once the animation has completed, a newtextvalue is shown immediately without replaying. - Line clamping. The component applies
lineClamp={1}by default to reduce layout shift as characters are revealed. You can override it by passing your ownlineClamp.
Recommended speeds and delays
typingSpeed is the pause between characters and delay is the wait before typing begins — both in milliseconds. Start from these values and adjust to the length and tone of the message.
Typing speed
| Speed | typingSpeed | When to use |
|---|---|---|
| Fast | 25 | Short confirmations, labels, and snappy inline responses. |
| Default | 50 | Standard assistant replies and chat messages. A good default. |
| Deliberate | 75–100 | Short, emphasized phrases where a slower reveal adds weight. |
Keep longer messages at 25–50ms so readers aren’t left waiting; reserve 75ms+ for brief text only.
Start delay
| Delay | delay | When to use |
|---|---|---|
| None | 0 | Begin typing immediately. The default for most cases. |
| Stagger | 150–300 | Let a preceding element (avatar, message bubble) settle before typing. |
| Thinking | 500–1000 | Suggest the assistant is “thinking” before an answer streams in. |
Use delays sparingly — anything beyond ~1s reads as lag rather than intent.
Best practices
Do
- Use it for streamed or assistant-style responses where the reveal reinforces that content is being generated.
- Keep
typingSpeedfast enough that readers aren’t waiting on the effect — see the recommended speeds and delays above. - Override
lineClampwhen the message is expected to wrap across multiple lines.
Don’t
- Don’t animate long-form or critical content a user needs to read immediately — the reveal delays comprehension.
- Don’t rely on the animation replaying when
textchanges after it has finished; it won’t.
Accessibility
Labeling & semantics
- The text is revealed character by character in the DOM and is not wrapped in an
aria-liveregion, so assistive tech is not notified as it types, and there is noprefers-reduced-motionhandling. Treat the animation as decorative. - When the message content matters for assistive tech, expose the full
textthrough a live region or a visually-hidden node you control, rather than depending on this component to announce it.
Properties
Component props
Prop | Required | Default | Type |
|---|---|---|---|
| text | true | string | |
| typingSpeed | false | 50 | number |
| delay | false | 0 | number |
| onComplete | false | () => void |
Inherited Text props
All props from the Text component are supported except children and ref. The most common ones:
Prop | Required | Default | Type |
|---|---|---|---|
| variant | false | 'body-normal' | TextVariant |
| color | false | 'foreground-2' | TextColor |
| align | false | 'left' | 'center' | 'right' | |
| truncate | false | false | boolean |
| lineClamp | false | 1 | 1 | 2 | 3 | 4 | 5 | 6 |
| wrap | false | 'wrap' | 'nowrap' | 'pretty' | 'balance' |