Skip to content
Design System
GitHub

Text diff

v0.16.2Beta

Where two texts differ, word by word: insertions a grey block with an underline, removals struck through, each announced to screen readers. Inline or side by side, with a +3 words, −1 word summary.

+5 words, −4 words

A added: yellow (end) forklift carries removed: two (end) added: three (end) pallets removed: across (end) added: past (end) the removed: warehouse floor. (end) added: loading dock. (end)

Text diff caption

Install
npx shadcn add @syncrobotic/text-diff

Also installs: @syncrobotic/cn

Overview

When to use

  • A base model's caption or answer against a fine-tuned one.
  • A label, prompt or description before and after an edit.
  • Reviewing a proposed change to a text before accepting it.

Use something else

  • A change of one value (a number, a setting): before → after in a timeline or audit row.
  • Code: a code diff viewer with lines and syntax.

More examples

States and real uses. Each example is also a Storybook story and a visual regression test.

+5 words, −4 words

A forklift carries removed: two (end) pallets removed: across (end) the removed: warehouse floor. (end)

A added: yellow (end) forklift carries added: three (end) pallets added: past (end) the added: loading dock. (end)

Text diff side by side

+13 words, −8 words

The image shows an indoor warehouse aisle with tall metal shelves on both sides. A worker in a removed: dark jacket (end) added: high-visibility vest (end) walks removed: towards (end) added: away from (end) the camera while a removed: small (end) added: delivery (end) robot waits near the left shelf. Boxes are stacked on the lower shelves and added: one box lies on (end) the floor removed: is clear of obstacles. (end) added: in the robot's path. (end) The lighting is bright and even.

Text diff long paragraph

No changes

Two people stand next to a charging dock.

Text diff no change

+7 words, −6 words

removed: A cat sleeps on a sofa. (end) added: Empty parking lot at night, three cars. (end)

Text diff all different

Usage rules

  • Inserted words are a grey block with an underline; removed words are struck through in secondary text. A removal is not an error: no danger, no green, no blue.
  • Inline for a sentence or two; side by side when people read each version whole. Side by side stacks when its container is narrower than 448 px.
  • Keep the summary line (+3 words, −1 word): it says how big the change is before anyone reads it.
  • Words are split on spaces, punctuation included; Chinese and Japanese by character.

Changelog

  • 0.16.22026-11-21tokenize gives back exactly its input for any text: spacing alone is one wordless token instead of none. A diff keeps that spacing as shared text, never as a word changed.
  • 0.16.12026-11-21Compiles with noUncheckedIndexedAccess, as strict products build it; behaviour unchanged.
  • 0.16.02026-11-19First release: TextDiff (before, after; inline or side-by-side) with a word-level LCS diff, <ins>/<del> announced as added and removed, a +N words, −N words summary, and diffWords/diffStats for counts elsewhere.

How to upgrade