TextDiff is a free online diff tool that finds the differences between two texts. Put two similar but slightly different texts side by side — a draft and its revision, the contract you sent and the one that came back, or the old and new versions of some code — and it color-codes which lines were added, deleted, or modified, and exactly which words or characters changed within each line.
All comparison happens inside your browser. The text you enter and the files you load are never sent to a server, so you can compare content you would rather not share outside, such as internal documents or contracts. The computation runs in a Web Worker, so the page stays responsive even with tens of thousands of lines.
Features
Line and in-line highlighting
After finding the changed lines, it highlights once more exactly which words, space-separated chunks, or characters changed inside them.
Split and unified views
Switch between a side-by-side view and a unified view that reads top to bottom, like git.
Ignore options
Compare while ignoring trailing whitespace, the amount of whitespace, all whitespace, letter case, or blank lines.
Line-ending normalization
Treats Windows (CRLF) and macOS/Linux (LF) line breaks as the same, and ignores whether the last line ends with a newline.
Sorted-key JSON comparison
Parses both JSON texts, sorts object keys, and re-indents them before comparing. Differences in key order alone are not reported.
Change statistics and navigation
Shows the number of added, deleted, and modified lines and a similarity percentage, and jumps straight to the previous or next change.
Changes only
Collapses long unchanged stretches and keeps 3 lines of context around each change. Click a collapsed section to expand it.
Drag and drop files
Drop .txt, .md, .json, .csv, or many kinds of code files onto a box, or drop two files at once to compare them immediately.
Patch and HTML export
Copy or save the result as unified diff (patch) text, or copy it as a colored HTML table to paste into an email or document.
How to use
- Paste the reference text in the left box (Original) and the text to compare in the right box (Modified). You can also drop a file onto a box or use the open button above it.
- With 'Compare as you type' on, the result appears as soon as you stop typing. With it off, press [Compare] or Ctrl+Enter.
- If needed, choose to ignore whitespace, case, or blank lines, pick the in-line diff unit (word, space-separated chunk, or character), or turn on JSON key sorting. Changing an option re-runs the comparison immediately.
- Choose split or unified view in the result bar, and move between changes with the up and down arrow buttons (or Alt+↑/↓).
- To share the result, copy or save it as a patch, or copy it as HTML.
Comparison options
| Whitespace: Compare as is | Spaces and tabs are treated exactly like any other character. A single difference in indentation makes the lines different. |
|---|---|
| Whitespace: Ignore trailing whitespace | Ignores only spaces and tabs left at the end of a line. Filters out differences caused by an editor stripping or leaving trailing spaces. (Similar to GNU diff -Z) |
| Whitespace: Ignore amount of whitespace | One space and several spaces count as the same. Whitespace versus no whitespace is still a difference: 'a b' and 'a b' are equal, but 'a b' and 'ab' are not. (diff -b) |
| Whitespace: Ignore all whitespace | Removes all whitespace before comparing, so even 'a b' and 'ab' count as the same line. (diff -w) |
| In-line diff: Word | Marks changes in units of letter/digit runs and symbols. Suited to code and English text. |
| In-line diff: Space-separated chunks | Marks changes in units of whatever lies between spaces. Useful for prose where you want to see whole phrases change, and well suited to languages such as Korean where particles attach to words. For languages written without spaces, such as Chinese or Japanese, the character unit is usually more useful. |
| In-line diff: Character | Compares one character at a time. Use it to pinpoint places where only a character or two changed, such as amounts, dates, or clause numbers. |
| Ignore case | Treats uppercase and lowercase letters as the same. |
| Ignore blank lines | Leaves out lines that are empty or contain only whitespace. Blank lines are shown in a faded color and are not counted as changes. (Similar to diff -B) |
| Normalize line endings | Treats CRLF, CR, and LF as the same line break and ignores whether the file ends with a newline. When off, a CR at the end of a line is shown as ␍ and a last line without a newline is marked with ∅. |
| Sort JSON keys | Parses both sides as JSON, sorts object keys alphabetically, and rewrites them with 2-space indentation before comparing. Array order is left unchanged. If parsing fails, the error position is reported. |
Line-ending differences (such as CRLF) are compared exactly only for text loaded from a file. Text pasted into the input boxes has its line breaks converted to LF by the browser, so CR differences do not show up.
Keyboard shortcuts
Ctrl+Enter / ⌘+Enter | Compare now |
Alt+↓ / Alt+↑ | Go to next / previous change |
n / p (outside the input boxes) | Go to next / previous change |
Tab (inside an input box) | Insert a tab character |
Your input is never sent anywhere
The comparison engine is JavaScript (diff-core.js) downloaded along with this page, and your text and files are processed only in browser memory. Your input is not saved; the browser only remembers your theme and option choices. When you close the page, your input is gone.
Frequently asked questions
Is the text I compare stored on a server?
No. Comparison is done solely by JavaScript in your browser, and your input is not sent to any server. Once the page is open, comparison works even if you disconnect from the network.
How large a text can I compare?
You can load a single file of up to 30 MB, and comparisons of tens of thousands of lines run in a separate thread (Web Worker), so the page does not freeze. When there are a great many differences, the tool may return an approximate rather than minimal result for speed. If the result exceeds 4,000 lines, only the changed parts are shown first.
Which algorithm does it use?
Line comparison uses Myers's (1986) O(ND) difference algorithm, implemented in its linear-space form. If the cost grows too large, it switches to approximate splitting, as GNU diff does. Inside changed lines, the same algorithm compares words, space-separated chunks, or characters again.
How are 'modified' lines distinguished from additions and deletions?
Within a changed block, if a deleted line and an added line are similar enough in content, they are paired as one edited line and counted as 'modified'. Lines without a match are counted as 'added' or 'deleted'.
How is similarity (%) calculated?
It is the share of unchanged characters among all characters on both sides (including line breaks). Identical lines count in full; for modified lines, only the parts that stayed the same within the line count as unchanged.
What is the difference between ignoring the amount of whitespace and ignoring all whitespace?
Ignoring the amount of whitespace only disregards how many spaces there are, so 'a b' and 'ab' are still different. Ignoring all whitespace removes every space before comparing, so the two are treated as the same. Use 'ignore all whitespace' with care in code where indentation matters, such as Python.
Can I apply a patch created with ignore options turned on?
The patch is built from the differences shown on screen, with context lines taken from the original. Differences hidden by ignore options are not included in the patch, so to reproduce a file exactly, turn off all options before creating the patch.
Can I compare Word, HWP, or PDF documents?
Not as files. Copy the text out of the document and paste it in to compare. Tables, footnotes, and formatting may be lost in the process. See the document comparison guide for tips.
Does it work on phones?
Yes. On narrow screens the input boxes stack vertically and the result starts in unified view. You can switch to split view as well.
Guides
- How Does diff Find Differences? — LCS and the Myers Algorithm
- Myers, Patience, Histogram — Comparing Diff Algorithms
- How to Read a Unified Diff (Patch) — A Guide for Code Review
- Whitespace Ignore Options Explained — diff -b, -w, -B, -Z and Their git Equivalents
- Comparing Documents and Contracts — How to Find Every Difference Between Two Versions
- How to Compare JSON — Sorting Keys and Normalizing
- Line Endings (CRLF, LF) and Invisible Differences — When Every Line Shows as Changed