Text compare: find the differences between two texts
To compare two texts, place them side by side and mark the lines that were added, removed or changed. A diff algorithm finds the longest common subsequence between the two versions so that only real changes are highlighted. This tool compares in your browser, shows insertions in green and deletions in red, and can switch between line, word and character granularity.
Your files never leave your device. Processing happens in your browser.How that works.
How it works
- Paste the original text on the left and the changed text on the right.
- Click Compare, or let it run automatically.
- Review highlighted additions and deletions; switch to word or character mode for finer detail.
Runs as JavaScript inside this tab. Turn off your connection after the page loads and it still works.
How diff works
The algorithm
A diff finds the smallest set of insertions and deletions that turns text A into text B. The classic approach, used by git diff, GNU diff and this tool, is Eugene Myers’ 1986 O(ND) algorithm, which searches for the longest common subsequence of tokens. Everything in that common subsequence is “unchanged”; everything else is an addition or a deletion. A “changed” line is simply a deletion next to an addition.
Granularity
| Mode | Token | Best for |
|---|---|---|
| Line | Each line | Code, config, CSV, lists |
| Word | Each word (and whitespace unless ignored) | Prose, contracts, articles |
| Character | Each character | Short strings, identifiers, finding a single typo |
Line mode is fastest and matches what version-control tools show. Word mode is what most people want for documents. Character mode can be noisy on long texts.
Reading a unified diff
--- original
+++ modified
@@ -1,4 +1,5 @@
function greet(name) {
- console.log("Hello, " + name);
+ console.log(`Hello, ${name}!`);
}
+greet("world");
---and+++name the two files.@@ -1,4 +1,5 @@is a hunk header: the hunk covers 4 lines starting at line 1 in the original and 5 lines starting at line 1 in the modified.- Lines starting with a space are context (unchanged),
-were removed,+were added. - Three lines of context surround each change so the patch can be applied even if line numbers shift.
Apply a unified diff with git apply changes.diff or patch -p0 < changes.diff.
Options
- Ignore whitespace treats runs of spaces and tabs as equal and ignores leading and trailing whitespace on each line. Use it to compare code that has been reformatted.
- Ignore case compares
Helloandhelloas equal.
Limits
- Moved blocks show as a deletion in one place and an addition in another; no diff tool in this class detects moves.
- Very large inputs (hundreds of thousands of lines) are supported but may take a few seconds; the work runs on your device.
- The comparison is textual. To compare JSON structurally, format both sides with the JSON formatter first so key order and indentation match.
Worked examples
Prose, word mode
Original: The quick brown fox jumps over the lazy dog. Changed: The quick red fox leaps over the lazy dog.
Result: brown red, jumps leaps. Two words removed, two added, seven unchanged.
Code, line mode
-function greet(name) {
+function greet(name, punctuation = "!") {
- console.log("Hello, " + name);
+ console.log(`Hello, ${name}${punctuation}`);
}
greet("world");
+greet("ToolsBoxx");
Two lines changed and one added. Side-by-side view pairs each removed line with the added line that replaced it.
Reformatted code with Ignore whitespace
Comparing a file before and after running a formatter with Ignore whitespace on reports “No differences” if only indentation and spacing changed, which confirms the formatter did not alter logic.
Finding one wrong character
Two 40-character API keys that look identical: switch to Character mode and the single differing character is highlighted.
Frequently asked questions
Can I ignore whitespace or letter case?
Yes. Toggle “Ignore whitespace” and “Ignore case” to compare only meaningful differences.
What is the difference between line and word diff?
Line diff marks whole lines that changed and is best for code and lists. Word diff highlights the specific words inside a line and is best for prose.
Is there a size limit?
No hard limit. Very large texts (hundreds of thousands of lines) may take a few seconds because the comparison runs on your device.
Are my documents uploaded?
No. Both texts stay in your browser. The share URL includes them only if you click Share and the total length fits in a link.
Text compare · last updated · changelog · part of Canned Tuna