Original
Changed
Differences
Paste or type text on both sides. The differences appear here as you type.
Ctrl+Enter run / or Ctrl+K search tools Press Ctrl+D to bookmark this page
How to compare two texts
- Paste or type the first version in Original and the second in Changed. You can also open or drop a text file on either side.
- The differences appear below as you type. Removed lines are marked
−and struck through, added lines are marked+and underlined, and inside a changed line the words that changed are highlighted. - Use Next and Previous, or the n and p keys, to jump from one change to the next. The keys do nothing while you are typing in a box.
- Turn on Show changes only to fold away the unchanged parts, keeping a few lines of context around each change.
- Press Copy or Download in the toolbar to get the changes as a standard unified diff.
Texts up to 1 MB are compared as you type. Between 1 and 5 MB, press Compare when you are ready, so typing stays smooth. Between 5 and 10 MB the texts are compared line by line first, and you can ask for word detail after. Each text can be up to 10 MB, because the comparison runs in your browser's memory.
Reading a diff
A diff lists the smallest set of lines you would need to remove and add to turn the original into the changed text. Lines that are the same on both sides are left alone. When a removed line and an added line sit next to each other, they are shown as one changed line, so you can see what happened to it.
Side by side puts the original on the left and the changed text on the right, with unchanged lines lined up across. It is easiest for reading edits to prose or settings. Unified shows one column: every removed line of a change, then every added line, the way git diff prints it. It is more compact and works on narrow screens, which is why phones always get it.
A block of text that moved to another place shows as removed in one place and added in the other. The comparison looks for the longest stretches that stay in the same order, as diff and Git do.
Word, character or no detail
Word detail marks the words that changed inside each changed line. It is the most readable choice for text, settings and most code. Character detail marks every single character, which helps with IDs, hashes, version numbers and typos. None shows changed lines whole, which is fastest for very large files.
Languages written without spaces between words, such as Chinese, Japanese and Thai, are split into words with your browser's built-in word segmenter. If your browser does not have one, those lines get character detail instead.
Ignoring whitespace, case, blank lines and line endings
- Whitespace: Ignore trailing treats lines as the same when they differ only in spaces or tabs at the end. Ignore all ignores every space and tab, so a change in indentation, or in the spacing inside a line, is not a difference.
- Ignore case treats
Erroranderroras the same. - Ignore blank lines leaves empty lines out of the comparison. They still show, marked as ignored.
- Ignore line endings is on by default. It treats Windows (CRLF) and Unix (LF) line endings, and a missing line break at the end, as the same. Turn it off to find them.
Ignore options never change your text. The result still shows each line as you wrote it, and a note tells you how many lines differ only in ignored ways. If nothing is left after ignoring, the result says so, with a Show them button that turns those options off again.
Why lines that look the same can be different
When a changed line looks exactly like the original, the difference is in a character you cannot see. The checker names it and marks it in the result. Your text is not changed: the marks are only drawn in the result.
| Difference | Marked as | Where it comes from |
|---|---|---|
| Trailing spaces or tabs | · | Spaces at the end of a line. Editors often add or remove them on save. |
| Tabs instead of spaces | → | The same indentation written with a tab on one side and spaces on the other. |
| Line endings | ↵ CRLF / ↵ LF | Windows ends lines with CR and LF, macOS and Linux with LF only. Git can change them on checkout. |
| Line break at the end | no line break | One side ends with a line break, the other does not. |
| Non-breaking spaces | [NBSP] | Looks like a space, but is a different character. Common in text copied from web pages and word processors. |
| Zero-width characters | [ZWSP], [ZWJ], … | Take no space at all. They slip in from copied text and break comparisons, keys and identifiers. |
| Byte-order mark (BOM) | [BOM] | An invisible marker at the start of some files saved as UTF-8, mostly on Windows. |
There are three results with no visible change, so you always know which one you have: the texts are identical; they are the same after the ignore options; or they look the same but differ in invisible characters.
The unified diff format
Copy and Download give you the changes as a unified diff, the format used by git diff, diff -u and code review tools:
--- original
+++ changed
@@ -1,4 +1,5 @@
name: shop-api
-port: 8080
+port: 9090
log_level: info
+retries: 3
timeout_seconds: 30 The @@ -1,4 +1,5 @@ line starts a hunk: it covers 4 lines of the original from line 1, and 5 lines of the changed text from line 1. Lines starting with a space are context, - lines were removed and + lines were added. Apply the downloaded file with git apply changes.diff, or with patch -p0 < changes.diff next to the original file.
The diff always includes every change, also the ones hidden by ignore options, so it applies cleanly. Open a file instead of pasting to have its file name in the --- and +++ lines.
How the similarity number works
Similarity is worked out on characters, not lines: 2 × unchanged characters ÷ (characters in Original + characters in Changed), rounded down to a whole percent. Identical texts are 100%, and texts with nothing in common are 0%. Line breaks are not counted, and an emoji counts as one character.
The unchanged characters of a changed line come from its word or character detail. When a line is shown whole, because detail is off or the line is very long, none of its characters count as unchanged, and the number is marked as approximate.
Your texts stay in your browser
The comparison runs on your device, in a background worker. Nothing you paste or open is uploaded. If "Remember my last input" is on in Settings, both texts and your options are kept in this browser only, so they are back when you return; texts over 1 MB together are not kept. Clear removes them.
Shared links carry your options. They include the two texts only if you tick that option, and only while the texts are short enough for a link. Anyone with such a link can read them. Everything goes after the #, which browsers never send to a server, and it is removed from the address bar when the link is opened.
Frequently asked questions
Is my text uploaded to a server?
No. The comparison runs in your browser, in a background worker, and nothing you paste or open is sent anywhere. If Remember my last input is on, both texts are kept in this browser only. Clear removes them.
How large can the texts be?
Up to 10 MB each. Texts up to 1 MB are compared as you type. From 1 to 5 MB you press Compare, and from 5 to 10 MB they are compared line by line first, with word detail on request.
Why do two lines look the same but show as changed?
They differ in a character you cannot see: a trailing space, a tab instead of spaces, a Windows line ending, a non-breaking space, a zero-width character or a byte-order mark. The checker names it and marks it in the result.
What is the difference between side by side and unified view?
Side by side shows the original on the left and the changed text on the right. Unified shows one column with removed lines marked - and added lines marked +, like git diff. Narrow screens always use unified.
Can I compare Word or PDF files?
Not directly. Only plain text files are read. Copy the text out of the document and paste it into each side, or save the document as plain text first.
Why does a moved paragraph show as removed and added?
A diff looks for the longest runs of lines that stay in the same order. A block that moved breaks that order, so it shows as removed where it was and added where it is now, as in git diff.
How is the similarity percentage worked out?
On characters: 2 × unchanged characters ÷ (characters in the original + characters in the changed text), rounded down. Line breaks are not counted. When some lines are compared whole, it is marked approximate.
Can I use the result with git apply?
Yes. Copy or Download gives a standard unified diff with 3 lines of context. It includes every change, even ones hidden by ignore options, so git apply and patch accept it.
Comparing texts in your code
Comparing two lists of lines and printing the changes, in Java, JavaScript, Python and Go. Python has a diff module in its standard library; for Java the snippet uses the usual library, and JavaScript and Go write the algorithm out.
Java
import com.github.difflib.DiffUtils;
import com.github.difflib.UnifiedDiffUtils;
import com.github.difflib.patch.Patch;
import java.util.List;
public class DiffDemo {
public static void main(String[] args) {
List<String> original = List.of("name: shop-api", "port: 8080", "log_level: info", "timeout_seconds: 30");
List<String> changed = List.of("name: shop-api", "port: 9090", "log_level: info", "retries: 3", "timeout_seconds: 30");
// Myers diff, line by line. Each delta is one change (changed, added or removed lines).
Patch<String> patch = DiffUtils.diff(original, changed);
// A standard unified diff with 3 lines of context, as git diff prints it.
List<String> unified = UnifiedDiffUtils.generateUnifiedDiff("original", "changed", original, patch, 3);
unified.forEach(System.out::println);
System.out.println(patch.getDeltas().size() + " changes");
}
} java-diff-utils (Apache-2.0), the usual Java diff library: io.github.java-diff-utils:java-diff-utils:4.12.
JavaScript
// Line diff with no dependencies, using the longest common subsequence.
// In a project, the diff package on npm (jsdiff, which this page uses) also
// gives word and character detail and unified patches: createTwoFilesPatch().
function diffLines(a, b) {
// lcs[i][j] = length of the longest common subsequence of a[i..] and b[j..]
const lcs = Array.from({ length: a.length + 1 }, () => new Array(b.length + 1).fill(0));
for (let i = a.length - 1; i >= 0; i--) {
for (let j = b.length - 1; j >= 0; j--) {
lcs[i][j] = a[i] === b[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
}
}
const out = [];
let i = 0;
let j = 0;
while (i < a.length && j < b.length) {
if (a[i] === b[j]) { out.push(` ${a[i]}`); i++; j++; }
else if (lcs[i + 1][j] >= lcs[i][j + 1]) out.push(`- ${a[i++]}`);
else out.push(`+ ${b[j++]}`);
}
while (i < a.length) out.push(`- ${a[i++]}`);
while (j < b.length) out.push(`+ ${b[j++]}`);
return out;
}
// split(/\r?\n/) also handles Windows line endings.
const original = 'name: shop-api\nport: 8080\nlog_level: info\ntimeout_seconds: 30'.split(/\r?\n/);
const changed = 'name: shop-api\nport: 9090\nlog_level: info\nretries: 3\ntimeout_seconds: 30'.split(/\r?\n/);
for (const line of diffLines(original, changed)) console.log(line); No dependencies. For word detail and patches, the diff package on npm (jsdiff) is what this page uses.
Python
import difflib
original = ["name: shop-api", "port: 8080", "log_level: info", "timeout_seconds: 30"]
changed = ["name: shop-api", "port: 9090", "log_level: info", "retries: 3", "timeout_seconds: 30"]
# A standard unified diff with 3 lines of context. lineterm="" because the
# lines have no line breaks of their own (use readlines() output as it is).
for line in difflib.unified_diff(original, changed, fromfile="original", tofile="changed", lineterm=""):
print(line)
# Similarity of the two texts, from 0 to 1, on characters.
ratio = difflib.SequenceMatcher(None, "port: 8080", "port: 9090").ratio()
print(f"similarity of the port lines: {ratio:.2f}") The difflib module in the standard library.
Go
package main
import (
"fmt"
"strings"
)
// diffLines compares two slices of lines using the longest common subsequence.
// Go's standard library has no diff package, so this is the whole algorithm.
func diffLines(a, b []string) []string {
lcs := make([][]int, len(a)+1)
for i := range lcs {
lcs[i] = make([]int, len(b)+1)
}
for i := len(a) - 1; i >= 0; i-- {
for j := len(b) - 1; j >= 0; j-- {
if a[i] == b[j] {
lcs[i][j] = lcs[i+1][j+1] + 1
} else {
lcs[i][j] = max(lcs[i+1][j], lcs[i][j+1])
}
}
}
var out []string
i, j := 0, 0
for i < len(a) && j < len(b) {
switch {
case a[i] == b[j]:
out = append(out, " "+a[i])
i++
j++
case lcs[i+1][j] >= lcs[i][j+1]:
out = append(out, "- "+a[i])
i++
default:
out = append(out, "+ "+b[j])
j++
}
}
for ; i < len(a); i++ {
out = append(out, "- "+a[i])
}
for ; j < len(b); j++ {
out = append(out, "+ "+b[j])
}
return out
}
func main() {
// Normalise Windows line endings before splitting.
original := strings.Split(strings.ReplaceAll("name: shop-api\nport: 8080\nlog_level: info\ntimeout_seconds: 30", "\r\n", "\n"), "\n")
changed := strings.Split(strings.ReplaceAll("name: shop-api\nport: 9090\nlog_level: info\nretries: 3\ntimeout_seconds: 30", "\r\n", "\n"), "\n")
for _, line := range diffLines(original, changed) {
fmt.Println(line)
}
} Standard library only: Go has no diff package, so the algorithm is written out. Needs Go 1.21 or later for max().
Last verified . Each example is run automatically and its output checked.