Skip to main content
ToolMaple

Text Compare (Diff Checker)

Compare two texts and highlight every difference.

Last updated:

6 lines

6 lines

Compare by
1 line added1 line removed3 lines changed2 lines unchanged
  • + added only in the changed text
  • − removed only in the original
  • changed changed an edited line: the old version above the new, the words that differ in a darker shade
Meeting notes, 12 March
Meeting notes, 14 March
Attendees: Ana, Ben, Chloe
Attendees: Ana, Ben, Chloe, Dev
Budget approved for the spring campaign.
Posters are still waiting for sign-off.
Launch date moves to 4 April.
Launch date stays at 28 March.
Action: Chloe sends the brief by Friday.
Next review in two weeks.

What counts as a difference, and how it is found

A diff answers one question: what is the smallest set of removals and additions that turns the original into the changed text? Everything the two versions share stays plain; everything else is marked. The search behind it is the algorithm Eugene Myers published in 1986, the one git uses by default, and short of the work limit described below, it finds a shortest answer rather than merely a plausible one.

A few rules decide what you see, and they are worth knowing before you trust a result:

  • A changed line is a pairing, not a fact. When a block of lines is replaced, each old line is matched with the new line that shares the most wording, in order. Matched pairs are shown old above new with the differing words darker; lines with no good match are plain removals and additions.
  • Line endings never count. A file saved on Windows (CRLF) and the same file saved on a Mac (LF) compare as identical, and so do two texts that differ only in a final line break.
  • Words include punctuation. In word mode a comma or a full stop is a word of its own, so adding one is counted. Chinese and Japanese, written without spaces, are compared one character at a time.
  • Ignored differences stay out of sight. With case or whitespace ignored, an unchanged line is shown as it appears in the changed text.

Line or word, and which boxes to tick

  • Line: code, configuration files, CSV rows, lists, subtitles and logs, anything where a line is a unit that means something on its own.
  • Word: prose. Contracts, essays, emails and translations keep a whole paragraph on one line, and line mode can only report that the paragraph changed.
  • Ignore whitespace: reindented code, text copied out of a PDF or an email, and in word mode a paragraph rewrapped at a different width.
  • Ignore case: SQL written in capitals by one person and in lowercase by another, headings converted to title case, email addresses and host names.
  • Hide unchanged lines: long files. Each change keeps three lines of context on either side, the same amount a unified diff shows, and the rest folds into a single line saying how much was hidden.

How to see what someone changed in a document

  1. Paste the version you sent into Original text and the one that came back into Changed text. The order matters: additions are what the second box has and the first does not. If the colours look backwards, press Swap.
  2. Switch to Word. Prose edits are usually a word or a phrase inside a long paragraph, and word mode marks exactly those.
  3. If either version passed through a PDF or an email, tick Ignore whitespace so that different line breaks do not bury the real edits.
  4. Read the counts first, then work through the highlights from the top. A number or a date changed inside a sentence is the edit people miss most often when reading two versions side by side.

How to compare two versions of a config file or snippet

  1. Stay on Line and keep Hide unchanged lines ticked, so a long file collapses to the parts that differ.
  2. Tick Ignore whitespace only when indentation carries no meaning. In Python and YAML it does, and ignoring it can hide a change that breaks the file.
  3. For JSON, format both documents the same way first with the JSON formatter, so that a minified version and a pretty one line up.
  4. Press Copy diff and paste the result into a pull request comment or a ticket, as described below.

Why the same change can be drawn two ways

A shortest diff is often not unique. Add a new function below one that ends in a closing brace, and the diff can mark your lines as added, or it can treat the old function’s closing brace as the end of your new one and your last brace as the end of the old one. The same number of changes, drawn differently, and both are correct descriptions of the edit. Myers’ method settles such ties the same way every time, which is why git offers alternatives such as --diff-algorithm=patience and histogram that try harder to anchor on lines that occur only once. If a result looks odd, check the counts: the number of changed lines does not depend on how the tie was settled.

Getting the result out of the page

  • Copy diff in line mode gives a unified diff: @@ headers with line numbers, then each line prefixed with a space, a minus or a plus, with three lines of context around every change.
  • Paste it into a fenced code block marked diff on GitHub or GitLab, and the removed and added lines are coloured for whoever reads the comment. Many other Markdown editors and chat apps do the same at the time of writing.
  • Copy diff in word mode writes removals as [-old-] and additions as {+new+}, which survives being pasted into a plain email.
  • Selecting by hand leaves out the line numbers and the plus and minus signs, so a copied block of unchanged lines pastes as clean text.
  • Nothing goes in the address bar. A copied link shares the tool, never the texts you compared.

The same comparison in Word, Google Docs, VS Code and git

  • Microsoft Word: Review, then Compare, then pick the original and the revised document. The result is a third document with the differences as tracked changes, formatting included.
  • Google Docs: Tools, then Compare documents. It produces a new document in which the differences appear as suggested edits.
  • VS Code: right click a file and choose Select for Compare, then right click the second one and choose Compare with Selected. From a terminal, code --diff old.txt new.txt opens the same view.
  • git: git diff --no-index old.txt new.txt compares any two files, even outside a repository. Add --word-diff for word mode, -b to ignore changes in the amount of whitespace, or -w to ignore whitespace entirely.
  • Command line: diff -u old.txt new.txt on macOS and Linux prints a unified diff; in the Windows command prompt, fc old.txt new.txt lists the lines that differ.

When to use which

The office suites are the right tool when formatting matters, since they compare bold, links and styles that plain text cannot carry. git and VS Code win for files you already have on disk. A page like this one wins for two snippets that only exist in a chat, an email and a web form.

What a diff cannot tell you

  • Invisible characters are real differences. A non-breaking space counts as whitespace and Ignore whitespace handles it; a zero width space does not, and neither does a Cyrillic letter that looks exactly like a Latin one.
  • Moves are not detected. A paragraph moved elsewhere shows as removed in one place and added in another.
  • Only characters compare. Bold, italics, links, fonts and comments do not survive a paste as plain text, so a change to them is invisible here.
  • Changed lines are an interpretation. A line rewritten beyond recognition appears as one removal and one addition, and the counts follow that choice.
  • Scripts without spaces compare in long runs. Thai, Lao, Khmer and Burmese have no spaces between words, so word mode treats each run between spaces and punctuation as one word.
  • Very different long texts hit a limit. Past a set amount of work the unaligned part is shown as one block out and one block in, with a note, rather than freezing the tab.

Frequently asked questions

How do I compare two texts and find the differences?

Paste the older version into the Original text box and the newer version into the Changed text box. The comparison runs as you type, so there is no compare button. Lines only in the changed text get a plus sign and a green background, lines only in the original get a minus sign and a red background, and an edited line shows its old and new versions one above the other with the words that differ in a darker shade. The counts above the result say how many lines were added, removed and changed.

What is the difference between comparing by line and by word?

Line mode treats each line as one unit, which is right for code, configuration files, CSV rows and lists, where a line means something. Word mode reads the text as one stream of words and punctuation and marks each word that was removed or added in place, which suits prose: an edited paragraph is usually a single long line, and line mode can only tell you that the whole paragraph changed. Line mode still highlights the words that changed inside an edited line.

Why does a line show as changed when I cannot see any difference?

Something invisible differs. The usual causes are a trailing space, a tab where the other version has spaces, a non-breaking space pasted from a web page or a word processor, a zero width space, or a letter from another alphabet that looks the same, such as a Cyrillic a in place of a Latin a. Tick Ignore whitespace to rule out the spacing. If the line is still marked, the characters really are different, and word mode will point at the exact word.

What exactly does Ignore whitespace ignore?

In line mode it ignores spaces and tabs at the start and end of each line and treats any run of spaces inside a line as one space, so reindented code and double spaces stop showing up. It does not ignore blank lines: an added empty line is still an added line. In word mode it ignores spacing and line breaks altogether, so a paragraph rewrapped at a different width compares as unchanged. Line endings, Windows CRLF against Mac and Linux LF, are always ignored, with or without the option.

Is my text uploaded anywhere?

No. The comparison runs in your browser, and neither text is sent to a server, written into the address bar or stored between visits. That makes it reasonable for a draft contract or a config file with internal host names in it, although for anything truly secret an offline tool on your own machine is the safer habit. The only thing recorded is an anonymous event saying the copy button was pressed and in which mode, never the text.

How does it decide that a line was changed rather than removed and added?

When a block of lines is replaced by another block, every old line is scored against every new line by how much of their wording they share, with longer words counting for more. Pairs that share roughly 40 percent or more, and keep their order, are shown as changed lines; the rest are plain removals and additions. That is why a rewritten sentence pairs with its new version even when the line above it was deleted, and why two unrelated lines are never forced into a pair just because they sit in the same position.

Why did a paragraph I only moved show as deleted and added?

A diff lists the fewest removals and additions that turn one text into the other, and it has no idea of a move. A paragraph moved from the top to the bottom is removed in one place and added in another. Some desktop tools detect moved blocks as an extra step; this one does not. To confirm that nothing else changed, move the paragraph back in a scratch copy of the new version and compare again.

What does the Copy diff button copy?

In line mode it copies a unified diff, the format git and the diff command print. Each group of changes starts with a header such as @@ -4,6 +4,7 @@, the first line number and length of the block in the original and in the changed text, followed by the lines themselves, prefixed with a space when unchanged, a minus when removed and a plus when added, with three unchanged lines of context around each change. In word mode it copies the text with removals written as [-this-] and additions as {+this+}, the notation of git diff --word-diff=plain.

Can I compare two files instead of pasting text?

Not directly. Open each file, select everything and paste it into the two boxes, which works for anything stored as plain text: code, CSV, JSON, Markdown, subtitles and logs. Word documents and PDFs need their text copied out first, and formatting such as bold or a changed font is not compared, only the characters. For files you compare often, git diff --no-index in a terminal or the compare view in VS Code works on the files themselves.

How long a text can it compare?

Two versions of the same document, a few thousand lines long and mostly unchanged, usually compare in a fraction of a second. The work grows with the number of differences, so two long texts with almost nothing in common are the slow case. To keep the tab responsive the comparison has a work limit; past it, the part it could not align is shown as one block removed and one block added, and a note above the result says so. The diff is still correct, just longer than it needs to be.

Sources

  • Eugene W. Myers, An O(ND) Difference Algorithm and Its Variations, published in the journal Algorithmica in 1986: the shortest edit script search and its linear space refinement, which this page implements.
  • Git documentation, git-diff, for --no-index, --word-diff, the whitespace options and the alternative diff algorithms.
  • The GNU diffutils manual, for the unified output format and its hunk headers.
  • MDN Web Docs, the del element, including why most screen readers do not announce it by default and the generated content technique used here to fix that.
  • W3C, Understanding WCAG 2.2: Use of Color, the reason every change also carries a sign, an underline or a strike through line.

More text tools

To count the words in each version, use the word counter. To make two versions comparable before diffing them, the JSON formatter lines up minified data and the text case converter evens out capitals. For a pattern that finds every place a phrase appears rather than what changed, try the regex tester.

Related tools

Privacy: the comparison runs entirely in your browser. Neither text is uploaded, written into the address bar or kept between visits, so closing the tab clears both. Pressing Copy diff records an anonymous analytics event naming only the mode, line or word, never the text.