Diff Viewer

Compare two texts and highlight differences

About Diff Viewer

Diff Viewer lists the differences between two texts in a single column, like a patch: each line is marked unchanged, removed (-), or added (+), with its number in the original and in the modified text. It uses the Myers algorithm (jsdiff library), so one inserted line is shown as one addition instead of shifting everything below it. When a line is replaced, the words that changed are highlighted inside both versions. Options ignore letter case, or spaces at line ends and the amount of space between words. Windows and Unix line endings compare as equal. Compare Text shows the same comparison in two columns.

Example

Output of the page's own comparison code; [-…-] and {+…+} stand for the words highlighted in red and green.

Original, then Modified

Original:
red
The cat sat on the mat
blue

Modified:
red
The dog sat on the mat
blue
green

Result (original line no., modified line no., line)

 1  1   red
 2    - The [-cat-] sat on the mat
    2 + The {+dog+} sat on the mat
 3  3   blue
    4 + green

How to compare two texts line by line

  1. 1Paste the first version in "Original" and the new version in "Modified".
  2. 2Check "Ignore whitespace" so that re-indented lines are not listed as removed and added, and "Ignore case" for changes of capitals only.
  3. 3Click "Compare"; the button stays gray until both boxes contain text.
  4. 4Read the list: a red line was removed, a green line was added, and the two numbers on the left give its line in each text.

Formats and limits

Input
Two pasted texts; there is no file upload
Options
Ignore case; Ignore whitespace (trims line ends and treats a run of spaces as one space)
Line endings
Windows, Unix, and old Mac line breaks are treated as the same
Result
One column with original and modified line numbers and word highlights; no download
Text size
The tool sets no size cap; above 1,000,000 characters a box shows only its first 20,000 characters, and the comparison still uses all of it

Where your texts are compared

Both texts are compared by code running in this page and are never sent to our servers or stored. The comparison library is downloaded with the page code the first time you click Compare. The result disappears when you reload, so copy what you need from it first.

Frequently asked questions

Can it ignore indentation changes?

Yes. With "Ignore whitespace" checked, a line whose indentation went from 2 to 4 spaces is listed once as unchanged, with its old and new line numbers, and a tab compares equal to a space. A space inserted inside a word still counts as a change.

Does it show which words changed inside a line?

Yes. When removed lines are followed by added ones, they are paired in order and the words that differ are highlighted inside each pair: red in the old line, green in the new one. Lines added or removed without a partner are shown whole.

Can I see the two texts side by side?

No. Diff Viewer shows one list with both line numbers, the way a patch reads. Compare Text, in the text tools, uses the same comparison engine and options and shows the two texts in two columns.

Do Windows line endings show up as differences?

No. CRLF, CR, and LF line breaks are all turned into the same break before comparing, so a file saved on Windows and the same file saved on Linux compare as identical.

Tips and tricks

  • ✓Comparing two versions of a JSON file? Format both with JSON Formatter first so that each value sits on its own line.