Skip to content

Text Diff Online — Compare Two Texts & LCS Diff Checker

Last verified May 2026 — runs in your browser

Original

Modified

Text Diff Online — Compare Text & Find Differences (LCS Algorithm)

Drop two versions of any text — a paragraph you rewrote, a config file before and after a change, two pasted log snippets, two drafts of an email — and the page paints additions in green, removals in red, and identical lines in muted grey. The comparison is real Longest Common Subsequence (LCS) diff, the same algorithm that powers `git diff` and Unix `diff(1)`, so when you insert a line at the top everything below stays "same" instead of cascading into a fake remove/add pair like simpler tools do. Useful for code review, contract redlines, comparing prompts you tweaked between LLM runs, A/B copy review, or auditing what changed in a YAML/INI/.env between two backups.

About this tool

The diff is a dynamic-programming LCS algorithm with O(n·m) time and memory — for two inputs of length n and m the page allocates an `Int32Array((n+1)×(m+1))` table to compute the longest common subsequence, then back-traces to emit additions, removals, and shared lines. Memory is capped at 4 million cells (~16 MB) — larger inputs auto-fall back to a fast naive line-by-line comparison so the page stays responsive instead of allocating gigabytes. The LCS path always picks the diagonal step ("same") when both lines match, and otherwise prefers the larger of (up, left) — this matches the standard Hirschberg/Hunt-Szymanski variant most diff tools converge on. Output preserves the original line order and surfaces moves correctly: deleting line 5 and adding the same line as line 8 shows as one remove + one add far apart, not eight lines of churn. Use cases: pull-request review when you want a quick diff without git, comparing two paragraphs of an article, finding what changed in a config file you backed up before a deploy, redlining a legal text, or reviewing two responses from the same LLM prompt to spot drift.

  • Real LCS diff — same algorithm class as git diff / Unix diff
  • Detects insertions and moves correctly (no fake remove/add cascades)
  • Color-coded output: green added, red removed, muted same
  • Memory capped at 4M cells; auto-fallback to naive diff above the cap
  • Reactive — re-diffs as you edit either pane
  • Side-by-side textarea input on desktop, stacked on mobile
  • Handles 2,000×2,000 line comparisons in milliseconds within the LCS cap
  • Empty lines diffed correctly (matter for ordering)
  • No upload — both texts and the diff stay in your browser
  • Useful for code review, contract redlines, config audits, LLM prompt drift

Free. No signup. Your inputs stay in your browser. Ads via Google AdSense (consent required).

Frequently asked questions

What is LCS, and why does it produce better diffs than line-by-line comparison?

A Longest Common Subsequence (LCS) is the longest sequence of lines that appear in the same order in both inputs (not necessarily contiguous). Hunt and Szymanski (1977, CACM 20(5):350–353) gave the original fast LCS algorithm; Hirschberg (1975, CACM 18(6):341–343) showed it can be computed in linear space; Myers (1986, Algorithmica 1:251–266) gave the O(ND) algorithm that powers git diff (default) and GNU diffutils (default heuristic variant). The LCS framing is 'what is the largest set of lines we can align between input A and input B?', and the diff is then 'everything in A but not in the LCS = removed; everything in B but not in the LCS = added; everything in the LCS = same'. Naive line-by-line diff (compare line 1 of A to line 1 of B, etc.) handles insertions and deletions poorly: a single line added at the top of B cascades into N remove/add pairs for everything below.

Why does the tool fall back to naive comparison above 4M cells?

The dynamic-programming LCS table is an Int32Array of size (n+1)×(m+1) where n and m are the line counts of input A and B. At 4 million cells the array uses about 16 MB of memory; for two 2,000-line inputs that is the boundary. Above the cap, allocating gigabytes of memory would crash the page or slow the browser to a halt. The fallback is a fast line-by-line comparison: walk both inputs in parallel, mark lines that differ at the same position. It is not as accurate as LCS — a single inserted line propagates into N differences below it — but it lets the page stay responsive on very large inputs rather than dying.

How does Myers' O(ND) algorithm differ from Hunt-Szymanski?

Hunt and Szymanski (1977) compute LCS in O((r+n) log n) time where r is the number of 'ordered pairs of matching positions' between A and B — fast when matches are sparse, slow when they are dense. Myers (1986) reframed LCS as a graph shortest-path problem and gave an O(ND) algorithm where N is the input length and D is the size of the resulting diff; for typical version-control diffs where most lines are unchanged (D is small), Myers is drastically faster. Hirschberg (1975) is a different optimization: applied to the standard O(nm) dynamic-programming recurrence, his divide-and-conquer construction reduces auxiliary space from O(nm) to O(n+m) at the cost of a roughly 2× time factor — so the same LCS algorithm can run on much larger inputs without the memory blowup. This page's implementation uses the straight quadratic dynamic programming because it produces edit scripts (added/removed/same) that match git diff-style output; Myers and Hirschberg are practical optimizations on top, not different output semantics.

Why does inserting a line at the top of input B not cascade as remove/add for the rest?

Because the LCS algorithm finds the longest common subsequence first, then derives the diff from it. If input A is `[a, b, c, d]` and input B is `[x, a, b, c, d]`, the LCS is `[a, b, c, d]` — every line of A appears in B in the same order. The diff result is 'B has one extra line (x) at the start' and the four trailing lines are marked 'same' on both sides. Naive line-by-line diff would compare A[0]=a to B[0]=x (different), A[1]=b to B[1]=a (different), and so on — every line propagates into a fake change. This is the practical reason git diff and Unix diff(1) use LCS rather than naive comparison: the patches stay minimal and human-readable even when content is rearranged.

How does this tool handle accessibility for screen readers?

The diff result region is marked aria-live="polite", the W3C WCAG Success Criterion 4.1.3 (Status Messages, introduced in WCAG 2.1, Recommendation 5 June 2018; carried unchanged into WCAG 2.2, Recommendation 5 October 2023) pattern. Polite live regions queue announcements after any speech in progress, so editing either input pane announces the new diff result without interrupting the user mid-sentence. Screen readers (NVDA, JAWS, VoiceOver) consume the live region automatically; the user does not need to do anything else.

Sources (5)
  • Myers, E. W. (1986). An O(ND) Difference Algorithm and Its Variations. Algorithmica, 1, 251–266 (DOI 10.1007/BF01840446) — the algorithm powering git diff and GNU diff.
  • Hunt, J. W., & Szymanski, T. G. (1977). A Fast Algorithm for Computing Longest Common Subsequences. Communications of the ACM, 20(5), 350–353 (DOI 10.1145/359581.359603).
  • Hirschberg, D. S. (1975). A Linear Space Algorithm for Computing Maximal Common Subsequences. Communications of the ACM, 18(6), 341–343 (DOI 10.1145/360825.360861).
  • ECMA International (2025). ECMAScript 2025 Language Specification — Int32Array typed array. ECMA-262, 16th edition, June 2025.
  • World Wide Web Consortium (W3C) (2018). Web Content Accessibility Guidelines (WCAG) 2.1 — Success Criterion 4.1.3 Status Messages. W3C Recommendation 5 June 2018; carried unchanged into WCAG 2.2 (Recommendation 5 October 2023).

These are the original publications the formulas in this tool are based on. Locate them by journal name and year on Google Scholar or PubMed.