---
title: "Text Streaming"
description: "Text that grows as it streams in, such as an AI answer: only the new end fades in, and nothing else moves."
url: https://gelatinui.com/components/text-streaming
markdown_url: https://gelatinui.com/components/text-streaming.md
access: free
install: "npx shadcn@latest add @gelatin-ui/text-streaming"
registry_item: https://gelatinui.com/r/text-streaming.json
version: "2026-11-14"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Text Streaming

> Text that grows as it streams in, such as an AI answer: only the new end fades in, and nothing else moves.

Page: https://gelatinui.com/components/text-streaming

## When to use it

Best for: An AI answer or other plain text that grows at its end while a stream sends it.

- Pass the whole text so far on each update; only the new end fades in.
- Put it inside the paragraph of a chat message: it is inline text, so the paragraph sets the size, the line height, and the wrap.
- Keep `animateInitial` off for a message that is there when the page loads, so a chat history shows at once.
- Set `aria-busy` on the message while it streams, and remove it when the stream ends.

## When not to use it

- For text that types in letter by letter with a caret, at its own pace, use [Text Typewriter](https://gelatinui.com/components/text-typewriter.md).
- For text that resolves from random letters, use [Text Scramble](https://gelatinui.com/components/text-scramble.md).

## Notes for agents

- `children` must be a string: the whole text so far, not the new piece.
- Each update that adds to the end is one chunk that fades in. A text that does not start with the last one (a new answer, an edit in the middle, a shorter text) shows at once, with no motion.
- It renders plain text in inline spans, with no Markdown. For Markdown, render the parsed text in your own parts.
- The text keeps its line breaks and spaces (`white-space: pre-wrap`), and a long word or link breaks so it never scrolls the page sideways.
- With `animateInitial`, a text in the server HTML stays hidden until hydration starts its fade, and stays hidden with no JavaScript.
- Nothing moves: only opacity and a small blur change, so a select or a copy during the stream gets the plain text.

## Anatomy

```text
TextStreaming
```

## API reference

### TextStreaming

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `string` |  | The text so far. Pass the whole text on each update (`"Hel"`, then `"Hello wor"`): only the new end fades in. A text that does not start with the last one (a new answer, an edit) shows at once, with no motion. |
| `animateInitial` | `boolean` | false | Fade in the text of the first render too. Default false: a message that is already there when the page loads (a chat history) shows at once. With it on, a text in the server HTML stays hidden until hydration starts its fade, and stays hidden with no JavaScript. |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| TextStreaming | `text-streaming` |  |  |  |

## Usage

Pass the whole answer so far. Only the new end fades in.

The sample also uses `card`, which this add does not write. One command adds them with this item:

```bash
npx shadcn@latest add @gelatin-ui/text-streaming @gelatin-ui/card
```

```tsx title="assistant-answer.tsx"
import { TextStreaming } from "@/components/text/text-streaming";
import { Card, CardContent, CardDescription, CardHeader } from "@/components/ui/card";

type AssistantAnswerProps = {
  /** The answer so far, from your model stream. */
  text: string;
  /** True while the model still sends tokens. */
  streaming: boolean;
};

export function AssistantAnswer({ text, streaming }: AssistantAnswerProps) {
  return (
    <Card aria-busy={streaming} className="max-w-xl">
      <CardHeader>
        <CardDescription>Assistant</CardDescription>
      </CardHeader>
      <CardContent>
        <p className="text-sm leading-6">
          <TextStreaming>{text}</TextStreaming>
        </p>
      </CardContent>
    </Card>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/text-streaming
```

It adds 4 registry items: 4 files, 668 lines, and the npm packages `clsx`, `motion`, `tailwind-merge`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Text Typewriter](https://gelatinui.com/components/text-typewriter.md)
- [Text Scramble](https://gelatinui.com/components/text-scramble.md)
- [Copy Button](https://gelatinui.com/components/copy-button.md)

## Motion

| Part | Motion |
| --- | --- |
| New text | reveal · 400ms · each new end fades in from 0 opacity and a 0.25em blur; the text before it does not change |
| Reset | none · a text that does not start with the last one shows at once |
