Diff Checker & Text Compare
Compare two texts side by side in your browser, nothing uploaded. Explains unified diff format and why CRLF line endings make every line look changed.
| 1 | function calculateTotal(price, tax) { | 1 | function calculateTotal(price, tax, discount = 0) { |
| 2 | const total = price + tax; | 2 | const subtotal = price - discount; |
| 3 | const total = subtotal + tax; | ||
| 4 | console.log("Total computed:", total); | ||
| 3 | return total; | 5 | return total; |
| 4 | } | 6 | } |
What Diff Checker & Text Compare Does
A diff finds the smallest set of changes that turns one text into another. Instead of comparing character by character, it solves a longest-common-subsequence problem, which is why a diff can recognize that a block moved rather than reporting the whole file as rewritten.
The granularity you choose changes what you see. A line diff marks an entire line as changed if one character differs. A word diff highlights just the altered words, which is what you want for prose. A character diff catches a single transposed letter that a line diff would bury.
Comparison here runs entirely in your browser, and nothing is uploaded. That is worth stating because the market leader in this category sells a desktop application specifically so that comparisons can be done offline, which tells you what the web versions do.
How to Use Diff Checker & Text Compare
- Paste your original text or code in the left box (Before)
- Paste your modified text or code in the right box (After)
- Choose between Side-by-Side Split view or Unified line view
- Optionally toggle Ignore Whitespace or Swap sides
- Inspect highlighted additions (green) and deletions (red)
How Diff Checker & Text Compare Works
Aligning two texts line by line
split both texts into lines → skip the shared first and last lines → find a shortest edit script with Myers' O(ND) algorithm → pair adjacent deletions and insertions as changed lines
- shortest edit script
- The fewest deleted plus inserted lines that turn the original into the modified text. It is the complement of the longest common subsequence of lines.
- Myers O(ND)
- Eugene Myers' 1986 algorithm, also used by git and GNU diff. Its cost grows with N (total lines) times D (number of differences), so near-identical files diff almost instantly.
- ignore whitespace
- Lines are compared with leading and trailing spaces trimmed, but shown exactly as typed.
Worked example
The sample on this page: a 4-line calculateTotal function against a 6-line version that adds a discount parameter and a log line
- Lines 1–2 of the original have no match in the new version: 2 deletions
- The new signature, subtotal line, total line and console.log line have no match in the original: 4 insertions
- " return total;" and "}" match, and stay aligned as unchanged
- Comparing position by position instead would pair line 3 with line 3 and report 0 matching lines
Result: +4 additions, −2 deletions, 2 matching lines.
Which Granularity to Use
| Mode | Best for | Weakness |
|---|---|---|
| Line | Source code, config files, logs | A one-character edit marks the whole line changed |
| Word | Prose, documentation, contracts | Noisy on code where whitespace is significant |
| Character | Spotting a transposed letter or stray space | Unreadable on anything large |
Reading a Unified Diff
The format git, patch and most tools emit. Worth being able to read directly.
| Marker | Meaning |
|---|---|
| --- a/file | The original ("from") file |
| +++ b/file | The new ("to") file |
| @@ -12,7 +12,9 @@ | Hunk header: from line 12, 7 lines became 9 lines |
| - removed line | Present in the original only |
| + added line | Present in the new version only |
| context line | Unchanged, shown for orientation (leading space) |
| \ No newline at end of file | One version lacks a trailing newline — a real difference |
Why a Diff Shows Changes You Cannot See
When "everything changed" but nothing looks different, it is almost always one of these.
| Cause | Symptom | Fix |
|---|---|---|
| CRLF vs LF line endings | Every single line marked changed | Normalize endings, or enable "ignore line endings" |
| Trailing whitespace | Lines look identical but differ | Strip trailing spaces, or ignore whitespace |
| Tabs converted to spaces | Whole file rewritten by an editor | Check your editor's indent settings |
| Byte order mark (BOM) | Only the first line differs | Save without BOM |
| Non-breaking space | A word looks the same but is not | Character-level diff will reveal it |
| Unicode normalization | Accented characters differ invisibly | Normalize to NFC before comparing |
How to Read Your Result
CRLF is the answer most of the time
Windows ends lines with carriage-return plus line-feed; Unix and macOS use line-feed alone. A file edited on both platforms, or checked out with the wrong git autocrlf setting, differs on every line while looking identical. If a diff claims a file was entirely rewritten and the author insists they changed one line, this is why.
A diff is not a merge
Finding differences is straightforward; deciding which side wins when both changed the same region is not. That is a three-way merge, and it needs the common ancestor as well as the two versions. A two-way diff can show you a conflict exists but cannot tell you how to resolve it.
Whitespace-insensitive diffs hide real bugs
Ignoring whitespace is the right default for reviewing prose or reformatted code. It is the wrong default for Python, YAML, Makefiles and anything else where indentation is syntax; there, a whitespace-only change can alter behavior completely.
Limitations & Accuracy Notes
- Comparison happens in your browser and nothing is transmitted. Very large inputs are limited by browser memory rather than by any server limit.
- This is a two-way text diff. It cannot perform a three-way merge, and it does not understand the structure of the content. A JSON diff tool will produce more useful output for JSON, because it compares values rather than lines.
- Binary files, images and PDFs are not supported; the tool treats input as text.
- Detecting a moved block depends on the algorithm and on how far it moved. Some moves are reported as a deletion plus an addition.
- Invisible characters (zero-width spaces, non-breaking spaces, differing Unicode normalization) are genuine differences and will be reported, which is usually what you want even when it is surprising.
- Past 3,000 differing lines the alignment stops and the rest of the middle is shown as one block removed and replaced. That keeps memory bounded on unrelated inputs, but the counts then describe that block replacement rather than the smallest set of changes.
Frequently Asked Questions
What is a Diff Checker?
A Diff Checker compares two texts or code files line-by-line to identify differences, showing additions in green, deletions in red, and unchanged lines.
Is my text sent to any server?
No, all text comparison happens 100% client-side in your browser. Your confidential code and documents never leave your computer.
Can I ignore whitespace differences?
Yes, check the "Ignore Whitespace" option to disregard leading and trailing spaces or tab variations.
Are my files uploaded?
No. Both texts are compared in your browser. That is the main reason to use a local diff for anything confidential (source code, contracts, configuration) rather than pasting it into a service that processes it server-side.
Does it compare line by line or word by word?
Line by line, which is the standard approach and matches what version control shows. A line with a single character changed appears as one removal and one addition rather than a highlighted character.
Why does it show every line as changed?
Almost always line endings. A file saved on Windows uses carriage return plus line feed while one saved on macOS or Linux uses line feed alone, and the difference is invisible on screen but present in every line. Normalizing line endings in both before comparing fixes it.
Can it ignore whitespace?
Trailing whitespace and indentation changes will show as differences unless you strip them first. This matters most when comparing code that has been through a formatter, where a large diff can be entirely reindentation.
Can I compare two files rather than pasted text?
Paste the contents of each. Because nothing is uploaded, there is no file handling step; the comparison works on whatever text you put in the two panes.
Is there a size limit?
No imposed limit. Very large inputs are constrained by browser memory, and the comparison itself gets slower as the number of lines grows.
References & Further Reading
- POSIX — diff utility (The Open Group Base Specifications) — The normative definition of diff behavior and output formats