A supplier sends back "the same" contract with a note that only the payment terms changed. A colleague edits the website privacy policy but forgets to turn on track changes. You have two versions of a configuration file and one of them works. In each case, reading both side by side and hoping to spot the difference is slow and unreliable.
This guide explains how text comparison ("diffing") works, what the different comparison methods are good at, how to run a quick comparison in your browser and what built-in alternatives exist in Word, Google Docs and on the command line.
What a diff actually shows
A diff is a list of differences between an original text and a modified text. Most tools present it in one of two ways:
- Unified view: one column, with removed lines marked
-(usually red) and added lines marked+(usually green). Unchanged lines provide context. - Side-by-side view: the two versions in parallel columns, with changed parts highlighted in each.
A changed line is normally shown as a removed old line followed by an added new line. That can look alarming at first, but it is simply the tool saying "this line was replaced by that one".
Line, word and character comparison
Tools compare at different levels of detail:
| Level | Good for | Weakness |
|---|---|---|
| Line | Code, lists, configuration files, CSV rows | One changed comma flags the whole line |
| Word | Prose, contracts, articles | Needs a smarter algorithm, slower on huge texts |
| Character | Short strings, IDs, spotting typos | Noisy on long texts |
Positional versus aligned comparison
The simplest method compares line 1 with line 1, line 2 with line 2, and so on. It is predictable and fast, and it works well when both versions have the same structure and lines were edited in place.
More advanced tools use an alignment algorithm (typically based on finding the longest common subsequence) to work out that a line was inserted, so everything after it can still match. This is what git diff and similar tools do.
The difference matters. With positional comparison, if one paragraph is added near the top, every following line shifts by one and is reported as changed. With an aligned comparison, only the added paragraph is marked. Good tools combine both levels: they align lines first, then compare paired lines word by word so you can see the exact edit inside a changed line.
Compare two texts in your browser
Our Text Compare diff checker aligns lines with the longest-common-subsequence method used by git diff (through the open-source jsdiff library), then highlights the changed words inside each edited line. It runs entirely in your browser, which makes it safe for internal documents.
- Open Text Compare.
- Paste the earlier version into Original text and the later version into Changed text, or click Open file above either box to load a plain-text file. Load sample shows two versions of a short terms-of-service text, and Swap exchanges the two sides.
- The result appears as you type. Choose Side by side to see both versions in parallel columns, or Unified for a single column with
-and+markers. Both views show line numbers for each version. - Read the colours: red lines exist only in the original, green lines only in the changed text, and a changed line appears red on one side and green on the other, with the differing words in a stronger shade. Under Highlight within lines you can switch to Characters for typos and IDs, or Off to mark whole lines only.
- Check the counters for Lines added, Lines removed, Lines changed and Unchanged. With Hide unchanged lines on, long identical stretches collapse to a "N unchanged lines hidden" bar with three lines of context around each change.
- Click Copy patch or Download .diff to save the result as a standard unified diff.
Because lines are aligned, inserting or deleting a line only marks that line; the text after it still matches. Ignore whitespace treats runs of spaces and tabs as one space and ignores spaces at the start and end of lines, and Ignore case treats capital and small letters as equal. These options only affect what is shown as different: the downloaded patch always describes the exact texts, so it can be applied with the patch command.
Preparing text for a cleaner comparison
A little preparation gives much clearer results:
- One sentence or item per line. A long paragraph is a single line, so one changed word pairs the whole paragraph as changed. The word highlighting still shows the edit, but splitting at full stops makes the line numbers and counts more useful.
- Normalise spacing. Invisible differences such as trailing spaces, tabs or double spaces are real differences to a diff tool. Turn on Ignore whitespace, or clean both versions with Remove Extra Spaces first if you also want the patch to ignore them.
- Sort lists first. If you are comparing two lists where order does not matter, such as email lists or product codes, sort both with Sort Lines so identical items line up.
Other ways to compare text
Microsoft Word
Word has a dedicated Compare feature on the Review tab (Compare → Compare…). Choose the original and revised documents and Word creates a third document showing insertions, deletions and formatting changes as tracked changes. For contracts and formatted documents, this is often the best option because it compares at word level and understands formatting.
Google Docs
Google Docs offers Tools → Compare documents, which produces a new document with the differences as suggestions. If both versions are the same file, File → Version history shows what changed between saved versions.
Command line and developer tools
On macOS and Linux:
diff -u original.txt modified.txt
prints a unified diff. Git users can compare any two files, even outside a repository, with git diff --no-index a.txt b.txt, and add --word-diff to see changes within lines. Most code editors also have a built-in compare view. These tools are the natural choice when the files already live in a repository; for text you have copied from emails, documents or web pages, pasting into a browser diff checker is usually faster.
Structured data and PDFs
Comparing JSON as plain text is fragile because key order and formatting can differ while the data is identical. Use JSON Compare, which compares the structure. For PDF files, Compare PDF extracts and compares the text; our guide on comparing two PDF versions covers that case in detail.
Tips for reviewing changes
Check the risky parts first
In a contract, look first for numbers, dates, names, notice periods and words such as "not", "shall", "may" and "exclusive". A single-word change there matters more than rewording elsewhere.
Don't trust "no differences" blindly
If a comparison shows no differences, confirm you pasted the right versions. It is surprisingly easy to paste the same text into both boxes.
Watch for look-alike characters
Curly and straight quotes, non-breaking spaces and different dash characters look identical on screen but are different characters. If two lines appear the same yet are marked as changed, invisible characters are the usual cause.
Keep an audit trail
For anything important, keep the original files. A diff shows you what changed, but the original documents are the record of what was agreed.
Frequently asked questions
What does the red and green highlighting mean?
Red marks text that exists only in the original, green marks text that exists only in the changed version. A line that was edited appears in both colours, and the words or characters that actually differ are highlighted more strongly.
Why is every line after a certain point marked as changed?
That happens with tools that compare lines by position, because one inserted or deleted line shifts all later lines. Our Text Compare aligns the lines first, so only the inserted or deleted lines are marked. If you still see a long block of changes, the lines really differ, often because of invisible whitespace or different line endings; try Ignore whitespace.
Can I compare two Word documents?
Yes. Word's Compare feature on the Review tab is the most complete option for formatted documents. You can also extract the plain text of each file and paste it into a text comparison tool.
Is my text uploaded when I compare it?
No. The Text Compare tool runs in your browser, so both versions stay on your device.
Does comparison ignore spaces and capital letters?
By default every character counts, including spaces and case. Turn on Ignore whitespace or Ignore case to treat lines that differ only in spacing or capitalisation as identical.
What is a .diff or patch file?
It is a text file in unified diff format: a header naming the two files, then "hunks" starting with @@ that list removed lines with -, added lines with + and a few unchanged lines for context. Developers use patches to share changes, and tools such as patch or code review systems can read them.