Text Diff Tool — Side-by-Side Comparison & Highlighting
Compare Two Texts
Paste the original text on the left and the modified text on the right. The diff engine compares them line by line with word-level highlighting. Everything runs in your browser — nothing is sent to a server.
Diff Output
What Is a Text Diff Tool?
A text diff (short for "difference") tool compares two versions of a text and visually highlights the changes between them. Additions, deletions, and modifications are displayed with color-coded highlighting so you can instantly see what changed, where it changed, and how it changed. Text diff tools are essential in software development for code review, in publishing for tracking editorial changes, in legal work for contract revision tracking, and in any workflow where multiple versions of a document need to be compared.
The concept of computing text differences dates back to the 1970s when the Unix diff command was created by Douglas McIlroy at Bell Labs. The underlying algorithm, based on the longest common subsequence (LCS) problem, was formalized by Hunt and McIlroy in 1976 and later optimized by Eugene Myers in his 1986 paper "An O(ND) Difference Algorithm and Its Variations." Today, diff algorithms power version control systems like Git, code review tools like GitHub's pull request view, and document comparison features in word processors.
This tool implements a line-level diff with word-level refinement. It first identifies which lines were added, removed, or modified using a longest common subsequence algorithm. For lines marked as modified (similar but not identical), it performs a second-pass word-level diff to highlight exactly which words within the line changed. This two-level approach provides both the structural overview of a line diff and the precision of a word diff.
How the Diff Algorithm Works
The diff computation follows a three-stage process. Stage 1: Line splitting. Both texts are split into arrays of lines. Empty trailing lines are preserved because whitespace changes can be meaningful (especially in code). Each line is assigned an index for position tracking.
Stage 2: Longest Common Subsequence (LCS). The engine computes the LCS of the two line arrays. The LCS identifies the longest sequence of lines that appear in both texts in the same order, though not necessarily contiguously. Lines in the LCS are "unchanged" — they exist in both versions at compatible positions. Lines in the original but not in the LCS are "removed." Lines in the modified text but not in the LCS are "added." Adjacent removed and added lines are paired as "modified" when their similarity exceeds a threshold (measured by the ratio of shared words to total words).
Stage 3: Word-level refinement. For each pair of modified lines, the engine splits both lines into words and applies a word-level LCS algorithm. Words present in the original but not in the modified version are highlighted as deletions (red background with strikethrough). Words present in the modified version but not the original are highlighted as additions (green background). This gives you precise character-level change visibility within modified lines.
Reading the Diff Output
The diff output uses a unified format with color coding. Each line is prefixed with a line number and a symbol indicating its status. Lines prefixed with "+" in green are additions: text that exists in the modified version but not the original. Lines prefixed with "-" in red are deletions: text that was in the original but was removed. Lines prefixed with "~" in amber are modifications: lines that exist in both versions but with changes. Within modified lines, the specific changed words are highlighted with green (added words) or red with strikethrough (removed words). Unmarked lines are unchanged context that appears identically in both versions.
The statistics panel shows four key metrics: total lines changed (the sum of additions, deletions, and modifications), the number of additions, the number of deletions, and the similarity percentage between the two texts. The similarity percentage is calculated as the number of unchanged lines divided by the total number of unique lines across both texts, giving you a quick measure of how different the two versions are.
Use Cases and Applications
Code review: Compare two versions of source code to identify what was changed in a commit, pull request, or patch. The monospace font and line-level precision make this tool suitable for reviewing code changes outside of a version control system.
Document editing: Compare a draft against a revised version to see exactly what an editor changed. This is particularly useful when receiving edits from a collaborator who does not use track changes or when comparing exported plain text from different document versions.
Configuration management: Compare two configuration files (JSON, YAML, INI, env files) to identify differences between environments (staging vs. production, local vs. remote). Mismatched configuration is a common source of deployment issues.
Content versioning: Compare published web content against a planned update to verify all intended changes are present and no unintended changes were introduced. This is a quality assurance step in content publishing workflows.
Legal document comparison: Compare two versions of a contract, agreement, or policy document to identify every change, addition, and deletion. In legal contexts, even minor wording changes can have significant implications.
Privacy and Performance
This text diff tool processes everything client-side in your browser using JavaScript. No text data is transmitted to any server. Diff computation typically completes in under 50 milliseconds for texts under 5,000 lines. For very long texts (over 10,000 lines), the LCS algorithm may take a few hundred milliseconds. All processing happens locally with no network requests. For full text analysis, the main Enhio text analyzer provides readability and style diagnostics. For image comparison, Krzen offers visual diff tools. Developers building diff pipelines may find HeyTensor's text processing utilities useful.
Need Full Text Analysis?
The main Enhio tool adds readability scores, sentence analysis, tone detection, and SEO keyword checking.
Open Full AnalyzerFrequently Asked Questions
How does the text diff algorithm work?
The diff tool uses a longest common subsequence (LCS) algorithm for line-level comparison, then performs a second word-level pass on modified lines. This two-level approach shows both structural changes (which lines were added, removed, or changed) and precise edits (which specific words within a line were modified). The LCS algorithm identifies the longest sequence of lines shared between both texts.
What do the different colors mean?
Green highlights indicate additions (text in the new version but not the original). Red highlights indicate deletions (text removed from the original). Amber/yellow highlights indicate modifications (lines that exist in both versions but with changes). Within modified lines, changed words are highlighted green (new) or red with strikethrough (removed) for precise identification.
Can I compare code with this tool?
Yes. This tool works with any plain text including source code, configuration files, JSON, XML, CSV, markdown, and prose. It uses a monospace font and preserves whitespace and indentation. However, it performs text-level diffing and does not understand language-specific semantics like variable renames or function moves.
Is there a size limit for comparison?
The tool handles texts up to approximately 50,000 characters per side with good performance. All processing happens client-side in your browser, so performance depends on your device. There is no server-side limit since nothing is transmitted over the network.
Is my text data private?
Yes. This text diff tool runs entirely in your browser using client-side JavaScript. Your texts are never sent to any server, stored, or shared. There are no cookies, no analytics, and no accounts. Verify this in your browser's Network tab.