DevTools Hub

Text Diff

Compare two blocks of text line by line, with the changed words highlighted.

Runs locally
Original56 chars
Changed73 chars
Diff+2-1
function greet(name) {
- console.log("Hello " + name);
+ console.log(`Hello, ${name}!`);
+ return true;
}
Status
2 additions, 1 deletion.

How it works

The comparison is line based and uses a longest common subsequence, the same idea behind diff and the side-by-side view in a code review. Lines that appear in both texts are aligned, and everything else is shown as an addition or a deletion.

Additions and deletions are counted and colour-coded. When a removed line pairs with the line that replaced it, the two are compared again word by word and only the words that differ are highlighted, so a one-word edit reads as a one-word edit.

Case and whitespace can be excluded from the comparison. With whitespace ignored, re-indented code and lines that differ only in spacing line up as unchanged, while the text itself is still shown exactly as you pasted it.

Very large comparisons are refused rather than left to hang: the cost of the algorithm grows with the product of the two line counts, so beyond about four million line pairs the tool asks you to compare smaller sections.

Frequently asked questions

Does it compare line by line or word by word?
Both. Alignment is line based, as in diff and git, so a changed line is reported as one deletion plus one addition. Within such a pair the words are then compared, and the parts that actually changed are highlighted inside the two lines.
Why is a moved block shown as a deletion and an addition?
A longest common subsequence has to keep the order of lines, so text that moved cannot be matched in both places. It appears removed where it was and added where it now is.
Does whitespace count as a difference?
By default yes: trailing spaces, changed indentation, and a tab replaced by spaces all make lines unequal. Turn on Ignore whitespace to collapse runs of spaces and drop leading and trailing space before comparing, which leaves only substantive changes.
Can I compare two files?
Open each file, copy its contents, and paste it into a panel. The tool works on text you paste rather than on file uploads, which is what keeps it entirely local.
Is the text I compare uploaded anywhere?
No. The diff is computed in your browser, so you can safely compare configuration files, contracts, or logs that should not leave your machine.