Diff checker: compare text and code side by side
A diff checker compares two versions of a text or file and shows what was added, removed or changed. It uses a longest-common-subsequence algorithm, the same idea behind git diff, so only real changes are highlighted. This tool runs locally, offers line, word and character granularity, can ignore whitespace and case, and produces a unified diff you can copy into a patch.
Your files never leave your device. Processing happens in your browser.How that works.
How it works
- Paste the original on the left and the modified version on the right.
- Pick line, word or character mode and any ignore options.
- Read the highlighted diff, or copy the unified diff output.
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
What is a unified diff?
The format produced by diff -u and git diff: lines starting with - were removed, + were added, and @@ headers give line ranges. Tools such as patch can apply it.
Can I compare JSON or code?
Yes. For JSON, format both sides first with the JSON formatter so that key order and indentation match; then only real value changes show.
Does it detect moved lines?
No. Like most diff tools, a moved block appears as a deletion in one place and an insertion in another.
Are my files uploaded?
No. Both texts stay in your browser tab.
Diff checker · last updated · changelog · part of Canned Tuna