Text diff
Compare two texts in your browser with Google's diff-match-patch. Additions and deletions are highlighted after semantic cleanup. Nothing uploaded.
Text diff compares two strings in your browser using Google's diff-match-patch library. Deletions appear with strikethrough, additions are highlighted, and unchanged text is shown normally. This is character-level comparison with semantic cleanup — not a line-based git diff. Nothing is uploaded.
How it works
- Paste your texts. Put the original version in the left box and the modified version in the right box.
- Click Compare. The tool runs
diff_mainfollowed bydiff_cleanupSemanticto find and group changes. - Review differences. Deleted text appears with strikethrough. Added text is highlighted. Unchanged text shows normally.
Character-level vs line-based diffs
This page compares two pasted strings with Google's diff-match-patch. Click Compare to run diff_main and then diff_cleanupSemantic. The result is a character-level list of equal / delete / insert hunks, rendered inline. It is not a line-based git diff and not CPython difflib (unified_diff, ndiff), which split on newlines first. Node has no stdlib diff. The page does not call diff_linesToChars (the library's optional line mode). For the how-to, see Compare Two Texts with diff-match-patch.
| Aspect | This page | Line-based |
|---|---|---|
| Granularity | Characters after semantic cleanup | Whole lines, then hunks |
| Library | diff-match-patch | git diff; CPython difflib |
| Line mode | Not used (no diff_linesToChars) | Default for git and unified_diff |
| Output | Inline HTML: strikethrough delete, highlight insert | Unified ---/+++/@@ or ndiff prefixes |
| Unicode | No normalize(); NFC ≠ NFD | Also raw unless you pre-normalize |
| Input | Two paste boxes; no file path | File paths or stdin |
NFC é (U+00E9) and NFD é (e + U+0301) are different strings here — Compare does not call String.prototype.normalize. To compose them first, use Unicode NFC / NFD. Replacements are a deletion next to an insertion; there is no single “changed” color and no unified-diff download. Newlines stay in the hunks and render as line breaks. The fox / dog pair is a character-level replace of brown→red, jumps→jumped, and lazy→sleeping. Nothing is uploaded.
Diff in Python
Compare on this page runs Google's diff-match-patch in the browser: diff_main then diff_cleanupSemantic. The fox / dog pair is a character-level replace of brown→red, jumps→jumped, and lazy→sleeping. CPython difflib is a different library. Pass lists of lines to unified_diff and ndiff — a bare str is not a line list (CPython 3.14 raises TypeError). Node has no stdlib diff. For the how-to, see Compare Two Texts with diff-match-patch.
Python with difflib.unified_diff
One line in each list, so the whole sentence is a replace — the same granularity as POSIX diff -u in the shell section, not this page's inline hunks:
import difflib
a = 'The quick brown fox jumps over the lazy dog.'
b = 'The quick red fox jumped over the sleeping dog.'
print(''.join(difflib.unified_diff(
[a + '\n'], [b + '\n'],
fromfile='original.txt',
tofile='modified.txt',
)))
# --- original.txt
# +++ modified.txt
# @@ -1 +1 @@
# -The quick brown fox jumps over the lazy dog.
# +The quick red fox jumped over the sleeping dog.Python with difflib.ndiff
Still line-based. The ? guides mark character edits inside the one changed line. They are not this page's strikethrough / highlight HTML:
import difflib
a = 'The quick brown fox jumps over the lazy dog.'
b = 'The quick red fox jumped over the sleeping dog.'
for line in difflib.ndiff([a], [b]):
print(line.rstrip('\n'))
# - The quick brown fox jumps over the lazy dog.
# ? - ^^^ ^ ^^^
# + The quick red fox jumped over the sleeping dog.
# ? ^^ ^^ + ^^^^^^Python with difflib.SequenceMatcher
Passing the two strings compares characters. CPython's matcher is a Ratcliff–Obershelp-style longest contiguous match, not Myers and not diff_cleanupSemantic. The opcodes below are not brown→red, jumps→jumped, and lazy→sleeping:
import difflib
a = 'The quick brown fox jumps over the lazy dog.'
b = 'The quick red fox jumped over the sleeping dog.'
sm = difflib.SequenceMatcher(None, a, b)
for tag, i1, i2, j1, j2 in sm.get_opcodes():
print(tag, repr(a[i1:i2]), repr(b[j1:j2]))
# equal 'The quick ' 'The quick '
# delete 'b' ''
# equal 'r' 'r'
# replace 'own' 'ed'
# equal ' fox jump' ' fox jump'
# replace 's' 'ed'
# equal ' over the ' ' over the '
# insert '' 's'
# equal 'l' 'l'
# replace 'azy' 'eeping'
# equal ' dog.' ' dog.'HtmlDiff.make_table is a stdlib HTML table, not this page's inline spans. get_close_matches ranks similar strings; it is not a diff. context_diff is the *** / --- form, still line-based. NFC é and NFD é differ here and in difflib. Compose first on the Unicode normalizer. Nothing is uploaded. There is no Download control on this page.
Diff in the shell
Compare on this page runs Google's diff-match-patch in the browser: diff_main then diff_cleanupSemantic. The result is a character-level list of equal / delete / insert hunks, rendered inline. POSIX diff compares two files line by line and writes the edits needed to turn file1 into file2. Identical files print nothing and exit 0. Differing files exit 1; errors exit greater than 1. Default output is ed-script style, not this page's strikethrough / highlight HTML. The fox / dog pair is one line in each file, so diff reports the whole line as a change; this page marks brown→red, jumps→jumped, and lazy→sleeping inside the sentence. echo appends a newline — use printf when you care about a missing final LF.
POSIX / GNU diff (Linux)
Two path operands. One may be - to read that side from stdin. Unified -u is POSIX (three lines of context). Header timestamps on --- / +++ vary by implementation — GNU includes milliseconds and a timezone offset:
printf '%s\n' 'The quick brown fox jumps over the lazy dog.' > original.txt printf '%s\n' 'The quick red fox jumped over the sleeping dog.' > modified.txt # Default: ed-script style. Exit 1 when the files differ. diff original.txt modified.txt # 1c1 # < The quick brown fox jumps over the lazy dog. # --- # > The quick red fox jumped over the sleeping dog. # POSIX -u: unified hunks (timestamps omitted; they vary) diff -u original.txt modified.txt # @@ -1 +1 @@ # -The quick brown fox jumps over the lazy dog. # +The quick red fox jumped over the sleeping dog.
macOS / BSD diff
Apple ships diff with the same short flags ( -u, -c, -b). From macOS Ventura the binary is Apple Diff (BSD-based). GNU long options such as --unified / --ignore-case and --color are not portable. Unified headers often omit milliseconds and the timezone offset:
diff original.txt modified.txt diff -u original.txt modified.txt printf '%s\n' 'The quick brown fox jumps over the lazy dog.' | diff -u - modified.txt
POSIX -b treats runs of whitespace as equal; this page does not. GNU/BSD -i ignores case — not POSIX, and not this page. GNU -w ignores all whitespace; GNU/BSD -q prints only that the files differ. Neither is this page's inline hunks. cmp reports the first differing byte, not a visual diff. git diff --no-index is git (a diff --git header), not POSIX diff. Process substitution diff <(printf …) <(printf …) is bash, not POSIX. Both operands as - is not a two-input pipe. diff -r walks directory trees; this page has two paste boxes and no file path. A missing final newline makes GNU print \ No newline at end of file. NFC é and NFD é differ here and in diff. Compose first on the Unicode normalizer. Windows has no POSIX diff unless you use WSL or Git Bash; fc is a different utility. Character-level vs line-based notes are in the table above and in Compare Two Texts with diff-match-patch.
FAQ
- Does this tool upload my text?
- No. All comparison runs in your browser using diff-match-patch. Your text is never sent to a server.
- What algorithm does the comparison use?
- Google's diff-match-patch library. It performs character-level diffing, then applies semantic cleanup to group changes into readable hunks.
- Is this a line-based git-style diff?
- No. This tool compares at the character level, not line by line. There is no unified-diff output or file upload support.
- How are replacements shown?
- Replacements appear as a deletion (strikethrough) next to an insertion (highlighted). There is no single "changed" color.
- Does comparison normalize Unicode characters?
- No. NFC é (U+00E9) and NFD e + combining acute (U+0301) are treated as different characters. Use the Unicode normalizer first if you need them to match.