Developer Tools

Diff Checker - Text Comparison Tool

Compare two texts side-by-side with line-by-line diff highlighting and word-level differences — and understand how the underlying diff algorithm actually decides what changed.

By InventiveHQ Team

A diff checker compares two blocks of text and highlights every line, word, or character that differs — additions in green, deletions in red — so you can see exactly what changed between two versions without reading both from scratch. Under the hood it computes the Longest Common Subsequence of the two inputs: the largest run of lines that appear in both, in the same order. Anything outside that common subsequence is reported as inserted or deleted, which is how the tool turns "these two files are different" into a precise, color-coded, line-by-line map of the change.

That's the summary an AI Overview can give you. What it can't do is run the comparison on your two versions. So paste them below — this diff checker runs entirely in your browser, uploads nothing, and highlights the differences instantly. Then keep reading for the part the summary skips: how to pick line-level vs word-level, when to ignore whitespace, and which diff algorithm produces the cleanest review.

Loading interactive tool...

How a diff engine decides what changed

A diff is not a character-by-character subtraction. The engine looks for the Longest Common Subsequence (LCS) — the biggest set of lines shared by both files in the same order — and treats those as anchors. Everything between the anchors is either something the old file had and the new one dropped (a deletion) or something the new file gained (an addition). The diagram below shows the alignment: matching lines stay put, and only the genuinely-changed lines get colored.

How a diff aligns two versions using the Longest Common Subsequence The original and modified text are lined up on their shared lines; unmatched lines are marked as a deletion in red or an addition in green. Original Modified const port = 3000; let cache = null; start(port); export default app; const port = 3000; start(port); log('ready'); export default app;

− deletion (not in Modified) + addition (new in Modified) — — — matched lines (LCS anchors) — — — Only unmatched lines are colored; everything anchored is "unchanged".

Because a change can be described in more than one valid way, two diff tools can color the same edit differently and both be correct — after you apply either result the files are identical. That freedom is exactly what the different algorithms exploit.

Advertisement

Diff algorithms compared

Git, GitHub, and most modern tools default to Myers' algorithm (Eugene Myers, 1986 — "An O(ND) Difference Algorithm and Its Variations"), but you can switch. The trade-off is between finding the mathematically shortest edit and finding the most readable one for a human reviewer.

AlgorithmWhat it optimizes forBest forWeakness
Myers (default)Shortest edit script (fewest inserts/deletes)General-purpose, fast on almost anythingCan align on repeated/blank lines and split changes oddly
MinimalAbsolute smallest diff, even if slowTiny files where you want the theoretical minimumSlower; rarely worth it in practice
PatienceAnchoring on lines unique to each sideRefactors, moved blocks, source code reviewSlightly slower than Myers
HistogramPatience's idea, tuned for speed and qualityThe best default for reviewing code changesMarginally more complex; still fast
Which should I use?Reviewing code: try histogram. Everything else: the myers default is fine.

Switch algorithms in Git with git diff --diff-algorithm=histogram, or set it permanently with git config --global diff.algorithm histogram.

Line-level vs word-level: a decision matrix

The single biggest quality lever in a diff is granularity. Line-level highlights whole lines; word-level highlights only the changed tokens inside a line. Neither is "better" — they suit different content.

Your contentUse this granularityWhy
Source code, config files (JSON, YAML, TOML)Line-levelLine boundaries are meaningful; a changed line usually means a changed statement
Prose, articles, documentationWord-levelA one-word edit shouldn't repaint the whole paragraph
Legal contracts, policy documentsWord-levelYou need to see the exact clause that moved, not the whole section
Long single-line strings (minified JS, URLs, CSV rows)Character-levelThere are no line breaks to anchor on
Reformatted code (reindented, tabs→spaces)Line-level + ignore whitespaceCollapses cosmetic noise so real logic changes surface
Data files where key order varies (JSON/YAML)Normalize first, then line-levelSort keys and pretty-print both sides so equivalent data doesn't read as different

Reading unified diff format

When you copy a diff out of Git or diff -u, you get unified diff format — the same thing patch tools and code review platforms consume. Each change block is a "hunk" with a header telling you where it lands:

@@ -12,7 +12,8 @@ function start(port) {
   const app = express();
-  let cache = null;
   app.listen(port);
+  log('ready');
+  metrics.mark('boot');
   return app;

The header @@ -12,7 +12,8 @@ means: in the old file the hunk starts at line 12 and spans 7 lines; in the new file it starts at line 12 and spans 8 lines. Lines with - were removed, lines with + were added, and unprefixed lines are unchanged context (usually three lines each side) that helps patch locate the hunk even if surrounding line numbers drifted. This is why a unified diff can be applied to a slightly different version of a file than the one it was generated from.

Common use cases

  • Code review — Compare two versions of a source file to see what a change actually touched before you merge it. Ignore whitespace to strip out reformatting noise, and reach for a histogram diff on gnarly refactors.
  • Document and contract comparison — Track revisions between drafts of an agreement, article, or spec. Word-level highlighting shows the exact clause that changed.
  • Configuration drift — Diff a known-good config against what's running in production to spot the one changed value that broke a deployment.
  • Debugging "identical" outputs — When two runs "should" produce the same output but don't, a diff pinpoints the byte that differs — a trailing newline, a locale-formatted number, a reordered key.
  • Verifying copied content — Compare an original against a suspected duplicate to see precisely which passages match and which were altered.

Need expert code review?

Our development team provides professional code reviews, security audits, and quality assurance for your applications.

Request Code Review

Frequently Asked Questions

What is the difference between line-level and word-level diff?

Line-level diff marks an entire line as added or removed the moment any character on it changes — fast, but it flags a whole paragraph when you only fixed a typo. Word-level (and character-level) diff runs the same comparison inside a changed line so you see exactly which words moved, leaving the rest of the line untouched. Use line-level for code and config where line boundaries are meaningful, and word-level for prose, contracts, and long sentences.

How does a diff tool decide what changed?

Most tools compute the Longest Common Subsequence (LCS) — the largest set of lines that appear in both files in the same order. Everything in the LCS is "unchanged"; everything else is an insertion or deletion. Git and the classic Unix diff use Myers' 1986 algorithm to find this efficiently. Because a diff is one of many valid ways to describe the same change, different algorithms (myers, minimal, patience, histogram) can produce differently-shaped but equally correct output.

Can I ignore whitespace changes when comparing?

Yes. Most diff checkers, and git diff -w / diff -b, offer options to ignore trailing whitespace, all whitespace, or blank lines. This is essential when comparing code that was reindented, had tabs converted to spaces, or picked up different line endings (CRLF vs LF) but is functionally identical. Turn it off when whitespace is significant — for example in YAML, Python, or Makefiles where indentation changes meaning.

Is my text uploaded to a server when I use this diff checker?

No. This diff checker runs entirely in your browser using client-side JavaScript. Neither the original nor the modified text leaves your device, so you can safely compare source code, contracts, API keys in config files, or any sensitive document without it being transmitted or logged.

What is unified diff format and where is it used?

Unified diff is the standard patch format produced by diff -u and git diff. Each change block ("hunk") starts with a header like @@ -12,7 +12,8 @@ giving the start line and length in the old and new files, followed by context lines, removed lines prefixed with -, and added lines prefixed with +. It is the format patch, git apply, and code-review tools consume, which is why it is the lingua franca of change.

Why do two diff tools show the same change differently?

Because there is rarely a single "correct" diff. When a block of similar lines is inserted (say, repeated closing braces or blank lines), the algorithm has to choose which existing lines to treat as unchanged. Myers optimizes for the shortest edit script, while patience and histogram anchor on lines that are unique to each side, which usually produces more human-readable results for source code. The files are identical after applying either diff; only the presentation differs.

Can I compare JSON, YAML, or XML with a plain diff checker?

You can, but a text diff compares characters, not structure — reordering keys or changing indentation shows up as changes even when the data is equivalent. For structured data, either normalize both sides first (sort keys, pretty-print with a consistent formatter) and then diff, or use a structure-aware comparison. Normalizing before diffing removes the noise so the real value changes stand out.

What is the best way to review a large diff?

Split it. Ignore whitespace to collapse reformatting noise, review one file or hunk at a time, and prefer word-level highlighting on prose so you are not re-reading unchanged text. For code, a patience or histogram diff aligns moved blocks better than the default, and reviewing the diff before merging — not the final file — keeps you focused on what actually changed.