Text Diff
|
Paste two text blocks and see additions and removals highlighted inline. Switch between word-level and line-level diff. Works on code, config files, JSON, and plain prose.
Word diff vs line diff
Word mode highlights individual added and removed words within the flow of text. Useful for prose, commit messages, and content edits where you want to see exactly which words changed.
Line mode highlights complete added and removed lines. Useful for code, config files, and structured data where changes are isolated to whole lines.
For structured data like JSON or YAML, format both sides consistently first (use the JSON Formatter if needed), then diff. Without consistent formatting, whitespace differences appear as changes.
See also: JSON Formatter
What it is useful for
Before/after inspection — paste generated output from two runs of a script, a code generator, or a template engine to verify that a change produced exactly the intended difference.
Config comparison — staging vs production environment variables, nginx configs, database migration scripts.
Content review — checking a revised paragraph against the original without a version control system.
API response comparison — two API calls that should return the same structure but differ in specific fields.
Compared to git diff
git diff is better for version-controlled code: it tracks history, shows file context, and handles renames. This tool is better for ad hoc comparisons where you have two text blobs and no repository.
For one-off comparisons during debugging or code review where you just need to see what changed, this is faster than setting up a git diff.
How to read the diff output
In line mode, each line is shown once. Lines that appear only in the left input (removed) are highlighted in red. Lines that appear only in the right input (added) are highlighted in green. Lines present in both remain unstyled.
In word mode, the diff runs within lines. Individual words added to the right input appear in green inline; words removed from the left appear in red with strikethrough. This makes it easy to see single-word substitutions without losing the surrounding context.
A large block of red followed immediately by a large block of green usually means a paragraph or section was rewritten rather than edited in place — the algorithm found it cheaper to delete the old block and insert the new one than to list individual word changes.
− The server returned a 404 error.+ The server returned a 200 OK response.The ~~old~~ new configuration was applied.Diffing JSON and config files
Comparing JSON directly often produces a noisy diff because field order and indentation differ between serializers. The recommended workflow: format both inputs first, then diff.
Step 1 — paste the first JSON block into the JSON Formatter and copy the formatted output. Step 2 — repeat for the second JSON block. Step 3 — paste both formatted outputs into the diff. The result shows only semantic differences, not whitespace noise.
For YAML and TOML config files, ensure consistent indentation (2 spaces vs 4 spaces, tabs vs spaces) before comparing. A single indentation mismatch causes every indented line to appear changed in line mode.
Environment variable files (.env format) are plain text — paste them directly. Line mode shows which variables were added, removed, or changed.
1. Format JSON A → copy
2. Format JSON B → copy
3. Paste A left, B right → diff{"a":1,"b":2} vs {
"b": 2,
"a": 1
} — key order + indentation differAfter formatting both: only value differences appearSee also: JSON Formatter
Frequently Asked Questions
- Why does the diff show everything as changed even when most text is the same?
- A small formatting difference — a trailing newline, leading whitespace, or tab vs space — can cause large sections to look different in line mode. Try word mode, or check for invisible whitespace differences at the start or end of the text.
- Can I compare JSON with the formatter output?
- Yes. Format both JSON blocks in the JSON Formatter first (to normalize whitespace and key order), then paste both into the diff. This isolates semantic changes from formatting differences.
- What algorithm does the diff use?
- The diff library uses a variation of the Myers diff algorithm, the same algorithm underlying git diff and most text comparison tools.
- Is there a size limit?
- No hard limit is enforced. Diffing very large inputs (tens of thousands of lines) may be slow in the browser because the diff algorithm is O(n²) in the worst case.
- Can I compare files with different line endings (CRLF vs LF)?
- Line endings can cause every line to appear different in line mode even when content is identical. Windows uses CRLF (\r\n) and Unix/macOS uses LF (\n). If the diff looks noisier than expected, convert both inputs to the same line ending before comparing. Most text editors have a line ending setting in the status bar.
- How do I compare only a section of a large document?
- Extract the relevant section from each document before pasting. There is no region selection — paste only the portion you want to compare. For large config files, this also makes the diff output easier to read since unrelated lines do not appear.