Text Diff Tool

Compare two text documents side-by-side to highlight additions, deletions, and line modifications.

How to Compare Text Documents Online

1

Paste Text Payloads

Paste your original text into the left editor and the modified text into the right editor.

2

Select Comparison Options

Toggle options for ignoring case differences or whitespace variations.

3

View Highlighted Diff

Click Compare Text Documents to inspect highlighted line additions (green) and deletions (red).

Tool Options

Side-by-Side & Inline Highlights

Renders visual highlights indicating added characters (green), deleted characters (red), or modified rows.

Whitespace & Case Sanitization

Ignore leading/trailing whitespace changes, line endings, or case sensitivity differences to focus on content updates.

Detailed Change Metrics

Calculates precise counts of added characters, removed lines, and unchanged metrics for audit logs.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the Text Diff Tool do?

The Text Diff Tool compares two text documents side-by-side or line-by-line, highlighting additions (green), deletions (red), and modified characters between original and updated versions. It calculates line-level additions and removals, computes similarity percentages, and allows ignoring leading/trailing whitespace variations or character case differences.

Core Concepts

Understanding line-by-line and character-level difference algorithms:

  • Line-Level Difference Detection: Identifies exact line additions, removals, and unchanged anchor rows with line number tracking.
  • Character Similarity Thresholding: Distinguishes between completely new lines and minor line modifications (typos, word adjustments) using character distance calculation.
  • Normalization Filters: Supports toggling whitespace ignorance (ignoring leading/trailing padding) and case-insensitive comparison.

How to use the tool?

  1. Paste Text Payloads: Paste your baseline (original) text document into the left editor and your updated text document into the right editor or click Load Sample.
  2. Configure Comparison Rules:
    • Check Ignore Leading/Trailing Whitespace Differences to ignore padding shifts.
    • Check Ignore Case Differences to focus exclusively on textual changes.
  3. Execute & Inspect: Click Compare Text Documents to review highlighted line additions, deletions, modifications, and summary counts.

Related Developer Utilities

If you work with text comparisons, line formatting, and document manipulation, explore these complementary tools:

REST API Integration

Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/text/diff) to programmatically compare two text documents line-by-line and character-by-character while highlighting additions, deletions, and line-level modifications.

API Request Parameters

Name Type Description Example
leftRaw String Original left text document payload string. "Line 1\nLine 2"
rightRaw String Modified right text document payload string. "Line 1\nLine 2 (modified)"
ignoreWhitespace Boolean Ignore leading/trailing line whitespace differences. Defaults to false. false
ignoreCase Boolean Ignore character casing differences. Defaults to false. false

API Request Payload Examples

cURL

curl -X POST https://blueutils.com/api/text/diff \
  -H "Content-Type: application/json" \
  -d '{
    "leftRaw": "Line 1\nLine 2",
    "rightRaw": "Line 1\nLine 2 (modified)",
    "ignoreWhitespace": false
  }'

Python

import requests

url = "https://blueutils.com/api/text/diff"
payload = {
    "leftRaw": "Line 1\nLine 2",
    "rightRaw": "Line 1\nLine 2 (modified)"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String jsonPayload = """
            {
                "leftRaw": "Line 1\\nLine 2",
                "rightRaw": "Line 1\\nLine 2 (modified)"
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/text/diff"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

API Response Parameters

Name Type Description Example
isValid Boolean Returns true if comparison succeeded. true
isIdentical Boolean Returns true if left and right texts are 100% identical. false
summary Object Summary detailing added, removed, and unchanged line counts. {"addedLines":1}
lineDiffs Array Array of line difference change objects with type, value, and line numbers. [...]

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "isIdentical": false,
  "summary": {
    "totalLinesLeft": 2,
    "totalLinesRight": 2,
    "addedLines": 0,
    "removedLines": 0,
    "modifiedLines": 1,
    "unchangedLines": 1
  },
  "lineDiffs": [
    {
      "type": "unchanged",
      "value": "Line 1",
      "leftLine": 1,
      "rightLine": 1
    },
    {
      "type": "modified",
      "oldValue": "Line 2",
      "newValue": "Line 2 (modified)",
      "leftLine": 2,
      "rightLine": 2
    }
  ]
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "Both left and right text inputs are required and must be strings."
}

Rate Limit Exceeded Response (HTTP 429 Too Many Requests)

{
  "error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}

Why use an API to compare text documents?

Integrating the Text Diff API into document review workflows, audit logging systems, or AI validation pipelines provides essential benefits:

  • Rapid Script Validation: Verifies code or document changes programmatically before saving versions to cloud databases.
  • Optimized Token Efficiency for AI Agents: LLMs struggle with character-level accuracy when comparing multi-paragraph text blocks. Calling the API returns deterministic diff arrays with zero token hallucination.
  • Deterministic Accuracy Without Hallucinations: Ensures 100% accurate Myers diff calculations across thousands of document lines.

Native Usage

How to compare text documents locally in terminal environments or scripts:

Windows (CMD / PowerShell)

# Compare two text files in PowerShell
Compare-Object (Get-Content file1.txt) (Get-Content file2.txt)

Linux / Unix (Bash)

# Using unified diff in Linux
diff -u file1.txt file2.txt

Python

Using Python difflib:

import difflib

with open("file1.txt") as f1, open("file2.txt") as f2:
    lines1 = f1.readlines()
    lines2 = f2.readlines()

diff = difflib.unified_diff(lines1, lines2, fromfile="file1.txt", tofile="file2.txt")
print("".join(diff))

Java

Using Java java.nio.file.Files:

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

public class TextDiffExample {
    public static void main(String[] args) throws Exception {
        List<String> f1 = Files.readAllLines(Paths.get("file1.txt"));
        List<String> f2 = Files.readAllLines(Paths.get("file2.txt"));

        System.out.println("Files match: " + f1.equals(f2));
    }
}

Frequently Asked Questions (FAQ)

How do I compare two text documents online?

Paste your original document into the left editor and your modified document into the right editor. The tool highlights additions, deletions, and modifications in real time.

Can I ignore case or whitespace differences when comparing?

Yes. You can toggle checkboxes in the toolbar to ignore leading/trailing whitespace changes or case sensitivity differences before running the comparison.

Does the diff tool show inline changes?

Yes. The dual-pane editor visually highlights line insertions (green), deletions (red), and modifications (yellow) directly within the textarea, alongside a compacted list summary.

How does it handle very large text payloads?

The underlying Myers Diff algorithm scales dynamically. For files exceeding the standard complexity bounds, it automatically switches to a linear fallback to prevent browser freezing.

Are my text documents uploaded to external servers?

No. All text diffing, line alignment, and comparison calculations execute 100% client-side directly inside your browser. Your documents and code files remain completely private.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.