What Is a Text Diff — and How Does It Work?
A diff (short for difference) is an operation that compares two texts and produces a description of what changed between them — which content was added, which was removed, and which stayed the same.
The ToolLance diff checker uses the LCS (Longest Common Subsequence) algorithm — the same algorithm that powers git diff, GitHub pull request diffs, and most version control systems. LCS finds the longest sequence of tokens (lines, words, or characters) that appear in both texts in the same order, then identifies everything that falls outside that sequence as a change.
This produces the minimal diff — the smallest set of additions and deletions that transforms text A into text B. That minimality matters: it means the diff focuses on what actually changed, not on arbitrary alignment choices.
How to Compare Two Texts Online (Step-by-Step)
Diff Modes — Line, Word, and Character: Which to Use
Choosing the right diff granularity determines how useful the result is. Too coarse and you miss important changes; too fine and the diff is noisy and hard to read.
| Mode | Granularity | Best for | Pro tip |
|---|---|---|---|
| Line diff | One line at a time | Code, config files, CSV, log files, JSON | Use with Ignore whitespace to skip indentation-only changes in reformatted code. |
| Word diff | One word / whitespace token at a time | Documents, articles, essays, legal text, blog posts | The default choice for document comparison — it shows exactly which words changed without hiding context. |
| Character diff | One character at a time | Typo detection, serial numbers, version strings, passwords, precise edits | Use when the texts are similar and you need to find very small differences like a single transposed letter. |
View Modes — Split, Inline, and Unified Patch
Original on the left, modified on the right. Changes highlighted in each panel. The standard view for comparing two versions.
Best for: General comparison — the most intuitive layout when you want to read both versions simultaneously.
Both additions and deletions appear in a single stream. Additions are green, deletions are red with strikethrough. More compact than split view.
Best for: Quick visual scanning when you want to see the full text with changes marked, without scrolling two panes.
Standard unified diff format (git diff output). Lines with + are additions, - are deletions, space-prefixed lines are context. Compatible with git apply and the Unix patch command.
Best for: Developers who need a patch file, code reviewers, and anyone integrating with version control workflows.
Unified Diff Format — What It Is and How to Use It
The unified diff format (also called patch format) is the standard output of git diff, diff -u, and every major code review tool. It encodes exactly what changed between two files in a compact, machine-readable text format:
--- original +++ modified @@ hunk @@ The quick brown fox -jumps over the lazy dog. +leaps over the lazy cat. This is unchanged context.
Lines starting with - were in the original (A) but not the modified (B). Lines starting with + are in B but not A. Lines starting with a space are unchanged context — they appear in both versions and provide surrounding reference.
To apply a downloaded patch file using Git: git apply output.patch. To apply using the Unix patch command: patch -p0 < output.patch.
Ignore Options — Case, Whitespace, and Blank Lines
Real-world texts often differ in ways that are not semantically meaningful — capitalization conventions, indentation style, blank lines between sections. The three ignore options let you filter these out so the diff focuses on the content that actually matters.
| Option | What it does | Example | Use when |
|---|---|---|---|
| Ignore case | Lowercases both texts before comparing | 'Hello' and 'hello' → treated as identical | HTML attributes, SQL identifiers, configuration keys, case-normalized data imports |
| Ignore whitespace | Trims lines and collapses internal spaces in line mode; skips whitespace tokens in word mode | ' hello world ' and 'hello world' → treated as identical | Comparing reformatted code, YAML re-indented configs, editors that auto-format on save |
| Ignore blank lines | Filters out empty or whitespace-only lines before comparing | Two blank lines between paragraphs vs one → not flagged as a difference | Comparing minified vs formatted code, data exports with variable blank line conventions |
Similarity Score — What the Percentage Means
The similarity score is calculated as:
- 100% — the texts are identical
- 80–99% — minor edits (typical for version updates, typo fixes)
- 50–79% — significant changes but shared structure (section rewrites)
- 20–49% — heavily rewritten content with some shared phrases
- 0–19% — largely different content
The similarity percentage is always character-level, regardless of which diff mode (line/word/char) is selected. It gives a quick summary of how much the texts share in common before you read the detailed diff.
How to Compare Code Files Online
Supported File Formats and Recommended Settings
| Format | Type | Recommended mode | Notes |
|---|---|---|---|
| .txt | Plain text | Word or Line | General-purpose text files |
| .md | Markdown | Word or Line | Documentation, README files |
| .json | JSON | Line | Format both inputs first with consistent indentation |
| .js / .ts | JavaScript / TypeScript | Line | Enable Ignore whitespace for reformatted code |
| .css | CSS / SCSS | Line | Enable Ignore whitespace for minified vs formatted |
| .html | HTML | Line | Use Line for structure, Word for content |
| .yaml / .yml | YAML | Line | Enable Ignore whitespace for indentation changes |
| .csv | CSV | Line | Sort rows before comparing to avoid false positives |
| .log | Log files | Line | Ignore blank lines option useful for sparse logs |
| .xml | XML | Line | Format both inputs consistently before comparing |
Who Uses a Text Diff Tool — Real-World Use Cases
| Who | Task | Settings | Tip |
|---|---|---|---|
| Frontend / backend developers | Compare two versions of a source file before and after refactoring | Line diff · Split or Unified | Enable Ignore whitespace if only indentation changed. Download .patch to share with teammates. |
| Technical writers and editors | See exactly which words changed between document drafts | Word diff · Split or Inline | Word diff shows sentence-level changes more clearly than line diff for prose. |
| SEO and content teams | Compare page content before and after a rewrite | Word diff · Inline | Similarity % tells you how much of the original content was kept — useful for understanding content freshness. |
| DevOps and system administrators | Compare config files or YAML manifests between environments | Line diff · Split | Enable Ignore whitespace for YAML files where indentation may differ. Enable Ignore blank lines for ini files. |
| Data analysts | Compare CSV exports from two time periods to find new or removed rows | Line diff · Split | Sort your CSV before pasting to avoid false diffs from row reordering. |
| Students and academics | Track edits between essay drafts, compare sources, check for unintended changes | Word diff · Split | The similarity score gives a quick sense of how much was rewritten between drafts. |
| Legal and compliance teams | Compare contract versions to find clause changes | Word diff · Inline | Enable Ignore case if capitalization conventions changed between versions. |
| API developers | Compare JSON responses from two API versions | Line diff · Split or Unified | Format both JSON blobs with consistent indentation using the JSON Formatter before pasting for the cleanest diff. |
How to Compare JSON Files Online
JSON comparison is one of the most common developer use cases for a diff tool — comparing API responses between versions, checking config file changes, or verifying that a data transformation produced the expected output.
The critical step before diffing JSON: format both inputs with consistent indentation. If one JSON blob uses 2-space indentation and the other uses 4-space (or was minified), almost every line will show as a difference even if the data is identical. Use the JSON Formatter to normalize both inputs to 2-space indentation first, then paste them into the diff checker.
Then use Line diff mode and Split view. Each changed property or value will show as a removed line (red) and an added line (green). The similarity score will reflect how much of the JSON structure is unchanged.
Privacy — Your Text Never Leaves Your Browser
All text comparison runs locally in your browser using JavaScript. No text, no files, and no diff results are sent to any server. This is especially important for:
- Source code — proprietary algorithms, unreleased features, internal APIs
- Legal documents — contracts, NDAs, employment agreements
- Medical or financial records — any document with personally identifiable information
- API responses — which may contain user data or authentication tokens
- Configuration files — which may contain credentials, secrets, or environment variables
You can verify this by opening your browser Network tab and confirming no outbound requests are made when you paste text and run the diff.
Related Tools
Comparing JSON files? Format both inputs with consistent indentation first using the JSON Formatter & Validator — it also catches syntax errors before you try to diff. Comparing CSS or JavaScript files and need to minify the result after reviewing? The CSS & JS Minifier handles that in one step. Comparing PDF documents rather than plain text? PDF Diff Tool extracts the text from both PDFs and runs a word-level comparison.
Frequently Asked Questions
What is a text diff checker?
A text diff checker compares two texts and shows exactly what changed — what was added, what was removed, and what stayed the same. This tool uses the LCS (Longest Common Subsequence) algorithm, the same algorithm used by git diff, to find the minimal set of changes.
What is the difference between line, word, and character diff?
Line diff compares entire lines — best for code and structured text. Word diff compares individual words — best for documents and prose. Character diff compares every character — best for finding exact typos and single-character changes.
What is unified diff / patch format?
Unified diff is the standard format used by git diff and code review tools. Lines with + are additions, lines with - are deletions, lines with a space are unchanged context. Download as .patch and apply with git apply output.patch or patch -p0 < output.patch.
Can I compare JSON or code files?
Yes. Upload any text-based file (.js, .ts, .css, .html, .json, .yaml, .csv, .log) or paste directly. Use Line diff for code. For JSON, format both inputs with consistent indentation using the JSON Formatter first. Enable Ignore whitespace for reformatted code.
What does the similarity percentage mean?
Similarity = (unchanged characters) ÷ (total characters) × 100%. 100% means identical. It reflects character-level similarity regardless of which diff mode is selected.
Is my text uploaded to a server?
No. All comparison runs entirely in your browser. Nothing is sent to any server — safe for private code, contracts, medical records, and any sensitive content.
What does Ignore whitespace do?
In line mode, it trims leading/trailing spaces and collapses internal spaces before comparing. A line with different indentation is treated as identical if the content matches. Use it when comparing reformatted or re-indented code.
How do I apply a downloaded .patch file?
With Git: git apply output.patch. With the Unix patch command: patch -p0 < output.patch. The patch applies the additions and deletions shown in the diff to the target file.
Can I compare document versions or track edits?
Yes. Paste the original version in pane A and the edited version in pane B. Use Word diff mode for documents. The diff highlights every word that was added or removed, with statistics showing how many words changed.
What does Ignore case do?
It lowercases both texts before comparing, so "Hello" and "hello" are treated as identical. Use when comparing HTML attributes, SQL identifiers, or any text where capitalization differences are not meaningful.
