---
title: "Text Diff Typing"
description: "A replay of a real edit: a cursor moves, deletes, types new words, and selects text in a line."
url: https://gelatinui.com/components/text-diff-typing
markdown_url: https://gelatinui.com/components/text-diff-typing.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/text-diff-typing"
version: "2026-11-15"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Text Diff Typing

> A replay of a real edit: a cursor moves, deletes, types new words, and selects text in a line.

Page: https://gelatinui.com/components/text-diff-typing

## When to use it

Best for: A short sentence that edits into a new one, like a replay of real typing.

- Use `loop` to play the edit again after `hold` seconds.
- Use `typeSpeed` for the seconds per letter.

## When not to use it

- For text that types in once with a caret, use [Text Typewriter](https://gelatinui.com/components/text-typewriter.md).

## Notes for agents

- Give the text before the edit in `from` and after it in `to`.
- `onComplete` runs when the edit ends.

## Anatomy

```text
TextDiffTyping
```

## API reference

### TextDiffTyping

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `locale` | `string` |  | The BCP 47 locale for the letter and word split (`Intl.Segmenter`). Default: the `DisplayLocaleProvider` locale, else `"en-US"`. |
| `from` | `string` |  | The text before the edit. |
| `to` | `string` |  | The text after the edit. |
| `trigger` | `ViewEntryTrigger` | "view" | When the edit starts: `view` (default) the first time it is on screen, `mount` at once. |
| `loop` | `boolean` | false | Play the edit again after a rest. Default false: the new text stays. |
| `typeSpeed` | `number` | DIFF_TYPING_TIMING.typeSpeed | Seconds per key typed. Moves and selections take a few keys each. Default 0.06. |
| `hold` | `number` | DIFF_TYPING_TIMING.hold | Seconds the new text rests before a loop plays again. Default 2. |
| `onComplete` | `function` |  | Called after the last key (never with `loop`). |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| TextDiffTyping | `text-diff-typing` | `data-phase` |  |  |

## Usage

Give the text before and after the edit.

```tsx title="release-note.tsx"
import { TextDiffTyping } from "@/components/pro/text/text-diff-typing";

export function ReleaseNote() {
  return (
    <section className="flex max-w-md flex-col gap-2 py-12">
      <p className="text-sm text-muted-foreground">Changed in the plan</p>
      <p className="text-2xl leading-snug font-medium tracking-tight">
        <TextDiffTyping
          from="We ship the new editor on Friday."
          to="We ship the new editor on Monday, after the design review."
          loop
        />
      </p>
    </section>
  );
}
```

## 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-pro/text-diff-typing
```

It adds 24 registry items: 23 files, 4012 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@xstate/react`, `clsx`, `motion`, `tailwind-merge`, `xstate`.

## 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 Streaming](https://gelatinui.com/components/text-streaming.md)

## Motion

| Part | Motion |
| --- | --- |
| Type | instant · 60ms a key by default (`typeSpeed`); the result holds 2s (`hold`) before a loop |
