Compare two texts and highlight word-level differences

Compare two drafts as word-and-punctuation tokens and expose the shortest sequence of additions and removals between them.

freeworks offlinenothing uploaded
ToolText Diff
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

Optional preprocessing lowercases the strings or collapses every whitespace run to one space before jsdiff tokenizes them. Its Myers-based pass produces ordered added, removed, and retained chunks, while displayed counters split those chunks on whitespace to count words.

  • Case and whitespace remain significant until their respective ignore controls are selected.
  • jsdiff documents that its default word tokenization uses regular expressions rather than locale-aware Intl.Segmenter dictionaries.

Worked example

Compare two sentences
Show word-level differences between two texts
Input
											Input1: The quick brown fox
Input2: The slow brown cat
										
Output
												Type       Value    Count
---------  -------  -----
unchanged  The      1
removed    quick    1
added      slow     1
unchanged   brown   1
removed    fox      1
added      cat      1
											

When to use this

Editors review paragraph revisions, support engineers compare expected and actual test output, and localization reviewers inspect message-catalog wording changes.

Edge cases

  • A comma-only edit appears in the change chunks but can add zero to both word counters because punctuation has no whitespace-delimited word.
  • Ignore-whitespace mode makes tabs, newlines, and repeated ordinary spaces equivalent before token comparison.
  • Chinese prose without spaces receives poorer word boundaries than a locale-aware Intl.Segmenter comparison.

References