What Is a Text Diff?
A text diff is a side-by-side comparison of two blocks of text that highlights exactly what changed between them. Additions are shown in green, deletions in red, and unchanged sections stay neutral — so you can see at a glance what was added, removed, or modified without reading both versions line by line.
Diffing is one of the oldest and most useful tools in computing. It powers version control systems like Git, code review tools like GitHub and Bitbucket, document comparison features in Google Docs and Microsoft Word, and file sync utilities like rsync and Dropbox. Whenever two versions of something need to be reconciled, a diff algorithm is doing the work behind the scenes.
How Diff Algorithms Work
At its core, a diff algorithm solves the longest common subsequence (LCS) problem: given two sequences, what's the longest chain of items that appears in the same order in both? Anything outside that chain is either an addition or a deletion.
The most widely used diff algorithm — the one Git uses — is called Myers' diff algorithm, published by Eugene Myers in 1986. It runs in O(ND) time, where N is the total length of both inputs and D is the number of differences. When two versions are similar, D is small and the algorithm runs very fast.
Modern tools add refinements on top of Myers' algorithm, including:
- Line-level diffing — splitting text into lines first, then computing the diff between line sequences. This is what Git shows you in a pull request.
- Word-level diffing — comparing individual words rather than lines. Useful for prose where one word changed inside an otherwise identical sentence.
- Character-level diffing — the finest granularity. Great for spotting typos or subtle changes in short strings.
- Semantic diffing — used by some code editors to understand that reformatting, renaming variables, or moving a block of code isn't a "real" change.
When to Use a Text Diff Tool
- Code review — compare a file before and after editing to see exactly what changed.
- Contract and legal documents — spot edits between two versions of an agreement without reading the entire document.
- Writing and editing — compare drafts to see what your editor changed.
- Configuration comparison — check whether a
config.json or .env file changed between environments. - Data validation — verify that two exports or database dumps match (or find where they don't).
- Translation work — compare translated strings against the original source.
- Debugging — compare logs from two runs to isolate what changed.
Understanding the Diff Output
Most diff tools use a standard set of symbols and colors:
- Lines with
+ (green) — added in the new version. These exist only on the right side. - Lines with
- (red) — removed from the old version. These exist only on the left side. - Lines with a space or nothing — unchanged. Present in both versions.
- Inline highlights — within a changed line, the exact characters or words that differ are highlighted to show the minimal edit.
Reading a diff is a skill worth developing. Once you get used to the format, you can scan hundreds of lines in seconds and spot the exact changes that matter.
Side-by-Side vs Inline Diff
There are two common layouts for displaying diffs:
- Side-by-side — original on the left, modified on the right, aligned so corresponding lines sit next to each other. Best for long documents and code, where you want to see context.
- Inline (unified) — both versions interleaved into a single column, with additions and deletions marked. More compact; standard in Git and code review tools.
Our tool supports both layouts — switch between them based on the task. Side-by-side is easier for prose and legal docs; inline is easier for code where you want to see the change in flow.
Character, Word, and Line Granularity
Diff tools work at one of three levels. This tool uses the line level, which suits code, lists and configuration files:
- Character — pinpoints single-character typos and whitespace differences. Best for short strings or critical precision.
- Word — highlights words that changed inside otherwise identical sentences. Ideal for prose editing.
- Line — treats each line as a unit. Best for code, configuration files, and structured data.
Why Privacy Matters for Diff Tools
The text you compare in a diff tool often contains sensitive information — legal contracts, code with API keys, private notes, customer data, or configuration secrets. Uploading it to a remote server for comparison is a real privacy risk. Our Text Diff Tool runs entirely in your browser using native JavaScript. Your text never leaves your device, never touches our servers, and is never logged. You can verify this by opening your browser's Developer Tools → Network tab — no requests are made when you paste or compare text.
A Worked Example
Type three lines in the Original box: apples, bananas and cherries, pressing Enter after each one. In the Modified box type apples, blueberries, cherries and dates, again pressing Enter after each. The result shows apples and cherries as plain lines in both panels, bananas in red under Original, and blueberries and dates in green under Modified. In other words, one line was replaced and one was added.
Now delete the final Enter in both boxes and look again. This time bananas and cherries are red, and blueberries, cherries and dates are green, even though cherries did not change. The last line of the original no longer ends with a line break, while cherries in the modified text still does, so the two lines are not identical. Ending both texts the same way fixes it.
Common Mistakes
- Texts that end differently. As the example shows, a missing final line break makes the last line look changed.
- Different line wrapping. Text copied from a PDF or email often has line breaks in different places, so almost every line looks changed. Put each paragraph, or each sentence, on its own line in both boxes before comparing.
- Invisible spaces. A space at the end of a line, or two spaces instead of one, is enough to mark the line as changed. If a line looks identical, check for these.
- Boxes the wrong way round. The older version goes in Original on the left. If you swap them, new lines show as removed and removed lines as added.
- Expecting word highlights. The whole line is marked even when only one word changed. Split long lines into shorter ones to narrow down the change.
Frequently Asked Questions
Is my text uploaded anywhere?
No. The comparison runs in your browser with the open-source jsdiff library. Nothing you paste is sent to our server, so it is safe for contracts, code and private notes.
Does the tool compare words or lines?
Lines. Each line is compared as a whole, so a line with one changed word is shown as removed in the original and added in the modified text. Put shorter pieces on separate lines for a finer comparison.
Why is a line marked as changed when it looks the same?
Usually because of something you cannot see: a space at the end of the line, a tab instead of spaces, a different capital letter, or a missing line break after the last line. Fix those and compare again.
What do the colours mean?
Red marks lines that are only in the original text. Green marks lines that are only in the modified text. Lines with no colour appear in both.
Can I compare two files?
Yes, by pasting their contents. Open each file in a text editor, select all, copy, and paste one into each box. There is no file upload, which keeps everything on your device.
Is there a size limit?
There is no fixed limit. Very long texts, such as tens of thousands of lines, can take a moment because the comparison runs on your own device.