Skip to content
Quaestio

Text compare

Paste the original and the changed version to have every difference highlighted, down to individual words.

Paste text into both fields to compare.

Embed

Embed this tool on your site

Copy the code and paste it where the tool should appear, such as a blog post or a school page. It is free, the box has no ads and the tool calculates in the visitor’s browser.

How it works

The comparison finds the shortest sequence of added and removed lines that turns one text into the other, using Eugene Myers’ algorithm from 1986. It is the same method git uses by default. Changed lines are then compared word by word so you can see exactly what differs.

Added lines have a green background and removed lines a red one. A changed line counts as one removed and one added, just as in other diff tools.

Ignore case treats Hello and hello as equal. Ignore whitespace disregards spaces at the start and end of a line and runs of several spaces, which helps when indentation has changed.

Unified diff is the text format produced by diff -u, with three lines of context around each change. It can be pasted into a bug report or read by patch and git apply.

Your texts never leave your browser. Very long texts that differ almost completely are not compared line by line; all lines are then shown as changed.

How the tool compares

First, identical lines at the start and end are set aside, since they cannot be part of any change. Between them, Myers’ algorithm finds the shortest sequence of removed and added lines. Line endings in CR LF or bare CR are turned into LF beforehand, so the same text from Windows and from a Mac counts as equal. Within a change, removed lines are shown before added ones, and they are paired in order for the word-by-word comparison. Words are split at spaces and punctuation, so a changed comma is marked on its own.

Worked example

Compare the lines apple, banana, cherry with apple, banana split, cherry, date, both with a line break after the last line. The algorithm keeps apple and cherry, removes banana and adds banana split and date: two lines added and one removed. The line banana split is paired with banana, and only the word split with the space before it is marked as new. In unified diff this is a single hunk headed @@ -1,3 +1,4 @@: it starts at line 1 in both texts and covers three lines of the old one and four of the new.

Without a line break after the last line, the result changes. Under GNU Diffutils a last line without a line break does not match the same line with one, and cherry was the last line only in the old text. The tool then shows cherry as removed and added, three lines added and two removed, and writes \ No newline at end of file after each text’s last line, as diff -u does. Side by side and in a single column, the removed cherry line is marked “no line break at end”, since it would otherwise look unchanged. Ignore whitespace disregards the difference.

Limits

The work is capped at 4,000 changes at line level. Two texts of 2,001 completely different lines each go over the limit, and all lines are then shown as removed and added without comparison. At word level the cap is 2,000 changes per pair of lines, and if more than 80% of the characters have changed, the line is shown whole without word marking.

What does not show

Moved blocks are not recognised, because the algorithm knows only removal and addition. Move the first two lines of a five-line text down to just before the last and the tool shows two lines removed and two added. Ignore whitespace collapses spaces within a line but does not remove them: a,b and a, b still count as different.

Sources

How the tools are checked