Text comparison (diff) is the process of automatically finding and displaying, in color, the differences between two texts, documents, or blocks of code. The goal is to see at a glance which parts were added, which were removed, and how similar the two versions are. This tool aligns the two texts using their longest common subsequence (LCS); parts found only in the first text are highlighted in red, and parts found only in the second text are highlighted in green.
How do you compare two texts?
- Paste / upload — enter the texts in the two boxes, or load them from a file.
- Choose a mode — line for code, word for plain text, character for the finest-grained difference.
- Options — ignore case, whitespace, or punctuation differences if needed.
- View — switch between side-by-side (two columns) and inline (combined) view.
What is a diff, and how does it work?
This tool uses its own vanilla-JavaScript implementation of the LCS (Longest Common Subsequence) algorithm — no external library is loaded. Any common leading and trailing sections of the two texts are trimmed first (in most edits, most of the text is unchanged), and dynamic programming finds the longest common sequence in the remaining middle section. This way, even texts with thousands of lines are processed quickly in your browser.
How is the similarity ratio calculated?
For example, if 90 of 100 words in two texts match, 6 words were removed, and 8 words were added, the similarity is (2×90) / (2×90 + 8 + 6) × 100 ≈ 92.8%. Character mode gives the most precise ratio; line mode measures structural similarity.