Line-by-Line · Word-level · Color Coded

Diff Checker

Compare two texts side by side to instantly see what was added, deleted, or changed. Line-by-line and word-level diff with color highlighting. No data sent to any server.

Last updated

Line-by-Line Diff
Word-Level Diff
100% Client-Side
Added · Deleted · Changed
Our networkLegalCost.usWhat will your legal case cost?Official formulas for all 50 states. Free, no signup.Check your state
↕️
Diff Checker: Text Comparison
Click Compare to see the diff

Text Diff Explained

A diff checker lines up two texts and marks every line that was removed (red, minus) or added (green, plus), using the smallest possible set of changes. Paste the original on the left and the new version on the right, then pick line diff for code or word diff to see exactly which words changed. Everything runs in your browser.

A diff (short for difference) algorithm compares two texts and identifies what changed between them. The classic algorithm, Longest Common Subsequence (LCS), finds the longest sequence of lines that appear in both texts in the same order: lines not in this sequence are either added or deleted.

The Unix diff command has been the standard for code comparison since 1974. Git, GitHub, and virtually all version control systems use diff under the hood to show what changed between commits.

How Diff Works

The Myers diff algorithm (1986) finds the shortest edit script (fewest insertions/deletions) to transform text A into text B. Lines prefixed with + were added (in B, not A). Lines with - were deleted (in A, not B). Lines with no prefix are unchanged context lines.

Line vs Word Diff

Line diff shows which entire lines changed. Word diff shows which specific words within a line changed. Word diff is more informative for prose editing: it shows "fox leaps" replaced "fox jumps" rather than just marking the whole line as changed. Git supports both with --word-diff flag.

Use Cases

Code review (finding what changed between versions), document editing (comparing draft versions), configuration management (spotting unintended changes), data validation (comparing expected vs actual output), plagiarism detection (finding identical or near-identical passages).

Privacy

This diff checker runs entirely in your browser: no text is sent to any server. This makes it safe for comparing sensitive documents, proprietary code, personal data, or confidential contracts. Close the browser tab and nothing is retained.

Worked Example: the Sample Texts

The two texts loaded on this page differ in three places. Line diff reports 3 lines deleted, 3 added and 2 unchanged: lines 1, 4 and 5 of A were replaced, while "Hello world" and "Line three" match.

LineLine diff showsWord diff marks
1Whole line removed and addedjumps to leaps, dog to cat
2 and 3UnchangedUnchanged
4Whole line removed and addedwill be deleted removed; is a brand new, added to B added
5Whole line removed and addedA to B

Word diff pairs the first removed line of a changed block with the first added line, the second with the second, and so on. Extra lines on either side are shown whole.

What Each Kind of Change Looks Like

ChangeResultTip
One word edited1 line removed, 1 addedUse word diff to see the word
Line inserted1 line added, nothing removedNothing to fix, it is a plain addition
Line movedRemoved in one place, added in anotherDiffs do not detect moves
Indentation or trailing spacesLines look the same but are markedTurn on Ignore whitespace
Tabs vs spacesMarked as changedIgnore whitespace treats any run of spaces or tabs as one space
Reformatted JSONMany lines changedFormat both sides the same way first

How the Comparison Works

The checker first skips the lines both texts share at the start and the end, then runs the Myers diff algorithm on what is left. Myers finds the shortest edit script, the fewest deletions and insertions that turn A into B, in time proportional to the text length times the number of differences, so two long files with a few edits compare almost instantly. Word diff runs the same algorithm again inside each changed line, on words, spaces and punctuation marks.

Line numbers refer to text A for removed and unchanged lines and to text B for added lines. Ignore whitespace compares lines after trimming them and collapsing runs of spaces and tabs, so a b and a b count as equal but ab and a b do not.

Tips for cleaner diffs

  • Format structured data before comparing: run both versions through the JSON formatter or the SQL formatter with the same settings.
  • Sort lists that have no meaningful order, such as dependency lists, so only real changes remain.
  • Compare plain text, not rich text. Copying from Word or a PDF can add invisible characters such as non-breaking spaces.
Method and sources. Diff algorithm: E. W. Myers, "An O(ND) Difference Algorithm and Its Variations", Algorithmica 1 (1986). Output conventions (minus for removed, plus for added) follow POSIX diff and git. The worked example counts were produced by running this page's diff code in Node.js on the sample texts.

Frequently Asked Questions

A diff checker uses the Longest Common Subsequence (LCS) algorithm or the Myers diff algorithm to find the minimum number of insertions and deletions needed to transform text A into text B. Lines that appear in both texts in the same order are "context" (unchanged). Lines only in A are "deletions." Lines only in B are "insertions." The result is displayed with color coding: green for additions, red for deletions, white/gray for unchanged lines.

Line diff marks an entire line as added or deleted if it changed at all: even a single character change shows the whole line as red (old) and green (new). Word diff goes deeper: it shows which specific words within a line changed, highlighting only the changed portion in a contrasting color. Word diff is more informative for prose and documentation. Line diff is standard for code where line-level context is more useful.

Yes: this diff checker runs completely in your browser (client-side JavaScript). No text is sent to any server. Your content is never transmitted, logged, or stored anywhere. This makes it safe for comparing confidential documents, private code, personal data, legal contracts, or any sensitive material. Refresh the page and all content is gone: nothing is retained.

Open both files in a text editor, select all content (Ctrl+A or Cmd+A), copy (Ctrl+C), and paste into the respective panels. For code files: open in VS Code or any editor, select all, copy, paste. For PDFs: open in a PDF reader, select all text, copy, paste (formatting may vary). For Word documents: open, Ctrl+A, Ctrl+C, paste the plain text version. File upload is not currently supported: this tool works with pasted text.

When "ignore whitespace" is enabled, lines that differ only in leading/trailing spaces or internal whitespace are treated as identical. This is useful when comparing code that may have been reformatted (indentation changes, trailing spaces cleaned up) without logical changes. Without this option, a line with extra leading spaces is treated as different from the same line without them. In git, the closest equivalent is git diff -b (ignore changes in the amount of whitespace); git diff -w goes further and ignores all whitespace, even between words.

If the files are in a Git repository: git diff file.txt shows unstaged changes. git diff HEAD~1 HEAD file.txt compares last two commits. git diff branch1..branch2 file.txt compares across branches. For two arbitrary files not in Git: diff file1.txt file2.txt (Unix/Mac) or FC file1.txt file2.txt (Windows). VS Code has a built-in diff view: Command Palette → "Compare Active File With..."

Green (+): Lines present in text B but not A, these were added. Red (-): Lines present in text A but not B, these were deleted. White/gray (no sign): Lines present in both texts, unchanged context. In word diff, green highlighting within a line shows added words; red strikethrough shows deleted words. This color convention follows the Unix diff standard and is used universally in Git, GitHub, GitLab, and all version control tools.

Yes, paste any text-based format: JSON, YAML, XML, HTML, CSS, JavaScript, Python, SQL, or plain text. For JSON specifically, consider formatting both versions first (use the JSON Formatter on this site) so the line structure is consistent and meaningful differences are more visible. For structured data, even a small change like adding a comma or changing indentation can affect many lines in unformatted JSON but only one line in properly formatted JSON.

Unified diff is the standard output format of the Unix diff -u command and Git. It looks like: --- a/file.txt (original file), +++ b/file.txt (modified file), then "hunks" starting with @@ -lineA,count +lineB,count @@ showing context lines, lines starting with - (removed), and lines starting with + (added). This format is used in patch files, code review systems, and bug tracking. It's compact (shows only changed sections with context) versus showing the entire file.

Word has a built-in track changes comparison: Review tab → Compare → Compare Documents, select the two versions and Word generates a marked-up document showing all changes. For a plain-text comparison, copy the text from both Word documents and paste into this tool. Microsoft Word's native comparison is better for documents with formatting, images, and tables, since it understands the document structure. This tool is better for comparing the raw text content when you don't need Word-specific formatting insights.

No. Like diff and git, it reports a moved line as removed where it was and added where it is now, because the shortest edit script is built from deletions and insertions only. If you moved a block of code, expect to see it twice, once in red and once in green.

The difference is usually invisible: trailing spaces, a tab instead of spaces, a non-breaking space pasted from a word processor, or different line endings. Turn on Ignore whitespace to skip spacing differences; in word diff the changed spot is highlighted even when it is only whitespace next to a word.