Skip to main content

📝 Text Diff

Compare two texts and highlight the differences line by line.

Your diff will appear here

About Text Comparison

The diff tool runs entirely in your browser using JavaScript, implementing a line-by-line comparison algorithm that identifies the longest common subsequence (LCS) between the original and modified texts. The LCS algorithm works by building a two-dimensional matrix where rows represent lines from the original text and columns represent lines from the modified text. It fills each cell by checking whether the corresponding lines match — if they do, the value is one plus the diagonal cell's value; otherwise it takes the maximum of the cell above or the cell to the left. After filling the matrix, the algorithm traces back from the bottom-right corner to reconstruct the edit path: lines present in both texts are marked as unchanged, lines only in the modified text are additions, and lines only in the original text are deletions. The result is displayed as a unified diff view with color-coded lines — green for additions, red for deletions, and gray for unchanged context — making it easy to see exactly what changed between two versions.

The algorithm handles several edge cases to produce useful output. Empty lines are treated as regular lines rather than being skipped, ensuring whitespace changes are detected. The comparison is case-sensitive and whitespace-sensitive by default, so indentation changes and capitalization differences are highlighted. The LCS approach minimizes the total number of edits needed to transform one text into the other, which produces the most intuitive diff output — it avoids showing a line as both deleted and re-added when it simply moved to a different position. For very large texts, the algorithm has O(N*M) time and space complexity where N and M are the line counts of the two inputs, which performs well for documents up to several thousand lines. The output preserves the original context around changes, showing a few unchanged lines between blocks of modifications to help you understand what changed and why.

Common Use Cases

Software developers use diff tools as a fundamental part of code review workflows, comparing proposed changes against the current codebase to identify bugs, style inconsistencies, and logic errors before merging. DevOps engineers compare configuration files across environments — development versus staging versus production — to catch discrepancies that could cause deployment failures. Technical writers and editors track document revisions between draft versions, identifying exactly what content was added, removed, or reworded. Security analysts compare system configuration files before and after an incident to identify unauthorized changes. QA engineers compare expected versus actual output to pinpoint the exact differences when test cases fail. Anyone debugging a regression can paste the working version and the broken version to see precisely what changed between them.

Security & Privacy Considerations

All processing happens entirely in your browser using JavaScript. Neither the original text nor the modified text is ever sent to any server, stored in cookies, written to local storage, or transmitted anywhere over the network. The comparison runs entirely in your browser's memory using standard Web APIs and is discarded when you navigate away from the page or close the browser tab. This client-side architecture makes the tool safe for comparing confidential source code, proprietary configuration files, sensitive legal documents, or any content you would not want to leave your device. No third-party analytics or tracking scripts have access to the text you compare. The tool functions completely offline once the page is loaded.

Frequently Asked Questions

Q: Is there a size limit?

The tool works well with texts up to several thousand lines. Very large inputs (tens of thousands of lines) may slow down the browser due to the O(N*M) matrix computation. For extremely large files, dedicated command-line diff tools with streaming algorithms are more appropriate.

Q: Does it support word-level diffs?

Currently the comparison is line-by-line. For word-level granularity within lines, specialized tools like git diff with the --word-diff flag or dedicated word-level diff libraries are better suited.

Q: Can it compare binary files?

No, the tool works with plain text only. Binary files contain non-text bytes that would produce meaningless character-by-character comparisons. Use specialized binary comparison tools like hexdump or xxd for binary file analysis.

Q: Does it handle encoding differences?

The tool compares raw text content as-is. Encoding differences between UTF-8 and ASCII may appear as spurious changes if the same characters are represented differently. Ensure both inputs use the same encoding for accurate comparisons.