ToolNimba

Dx Diff Checker, Compare Two Texts Line by Line

Shihab Mia By Shihab Mia ยท Updated 2026-07-06

Result 0 added 0 removed 0 unchanged

This diff checker compares two blocks of text line by line and shows you exactly what changed: lines that only appear in the new version are marked as added in green with a plus sign, lines that only appear in the original are marked as removed in red with a minus sign, and lines that match stay plain. It works out the differences by finding the longest common subsequence of the two line lists, which is the same core idea used by Git and most code review tools, so unchanged lines are kept together instead of everything after a single edit lighting up as changed. Everything runs in your browser, so nothing you paste is ever uploaded.

What is the Diff Checker (Text Compare)?

A diff checker answers one question: what is different between version A and version B of a piece of text. The naive way to do this is to line the two texts up row by row and compare line 1 to line 1, line 2 to line 2, and so on. That falls apart the moment you insert or delete a single line near the top, because every line after it shifts by one and the tool reports the entire rest of the document as changed. A real diff has to be smarter about lining the two versions back up.

The method this tool uses is the longest common subsequence, usually shortened to LCS. A subsequence is any set of lines you can get by deleting some lines from a list without reordering the ones that remain. The longest common subsequence of the two texts is the largest set of lines, in order, that appears in both. Those shared lines are the anchor: they are the unchanged part of the document. Anything in the original that is not part of that shared backbone is a removed line, and anything in the new version that is not part of it is an added line. Because the shared lines are matched by content rather than by position, inserting one line at the top no longer marks the whole file as changed.

Concretely the tool splits each text on line breaks into two arrays of lines, builds a table of LCS lengths comparing every tail of the first array against every tail of the second, and then walks that table from the start. At each step it either records a matching line (advancing in both texts), a removed line (advancing only in the original), or an added line (advancing only in the new text), choosing removals or additions based on which path preserves the longer common subsequence. The result is the familiar unified list of minus lines, plus lines, and unchanged lines, along with a count of how many were added and how many were removed.

Two options change how lines are matched without changing what is displayed. Ignore leading and trailing spaces treats two lines as identical when they differ only in surrounding whitespace, which is handy when indentation or a stray trailing space would otherwise flag a line as changed. Ignore case treats uppercase and lowercase as the same, so a heading that was recapitalized is not reported as a difference. Both options affect only the comparison; the original text of each line is always shown exactly as you pasted it.

When to use it

  • Comparing two drafts of an article, contract, or email to see precisely which lines were edited before you accept the changes.
  • Reviewing a code snippet or config file against an earlier version when you are not using a full version control diff.
  • Checking a list of records, SKUs, or email addresses against a previous export to spot which entries were added or removed.
  • Proofreading a translation or rewrite against the source, line by line, without missing a deleted sentence.
  • Verifying that a copy and paste or a find and replace only touched the lines you expected and nothing else.
  • Teaching or documenting how a text changed by producing a clean added and removed summary you can copy.

How to use the Diff Checker (Text Compare)

  1. Paste the original version into the left box and the new version into the right box, one item per line.
  2. Optionally tick Ignore leading/trailing spaces or Ignore case to relax how lines are matched.
  3. Read the result: green plus lines were added, red minus lines were removed, plain lines are unchanged.
  4. Check the counts at the top for how many lines were added and how many were removed.
  5. Click Copy diff to grab the unified diff, or Swap sides to compare in the other direction.

Formula & method

Split each text into a list of lines. Find the longest common subsequence (LCS) of the two lists: the longest ordered set of lines present in both. Build an LCS length table dp[i][j] over the tails of each list, where dp[i][j] = dp[i+1][j+1] + 1 if line a[i] equals line b[j], otherwise dp[i][j] = max(dp[i+1][j], dp[i][j+1]). Walk the table from the start: on a match, output an unchanged line and advance both; otherwise output a removed line (advance the original) or an added line (advance the new text) depending on which keeps the longer subsequence. Added = lines only in the new text; Removed = lines only in the original.
Diff Checker: match shared lines, mark the rest added or removedOriginalChangedline oneline twoold third lineline fourline oneline twonew third lineline four+ added (only in changed)- removed (only in original)unchangedResult: 1 line added, 1 line removed, 3 lines unchanged

Worked examples

One line changed in the middle of a four-line list.

  1. Original lines: L1, L2, L3, L4. New lines: L1, L2, X, L4.
  2. The LCS of the two lists is L1, L2, L4, which appears in both in order.
  3. L1 and L2 match, so they are unchanged.
  4. L3 is in the original but not the LCS, so it is marked removed (- L3). X is in the new text but not the LCS, so it is marked added (+ X).
  5. L4 matches at the end, so it is unchanged.

Result: 1 line added, 1 line removed; L1, L2, and L4 stay unchanged.

A new line inserted at the top, everything else identical.

  1. Original lines: Alpha, Beta, Gamma. New lines: Intro, Alpha, Beta, Gamma.
  2. A position-by-position compare would flag every line as changed because each shifted down by one.
  3. The LCS is Alpha, Beta, Gamma, which is the entire original in order.
  4. Only Intro is outside the shared backbone, so it is the sole added line.

Result: 1 line added, 0 lines removed; Alpha, Beta, and Gamma are unchanged.

How each line is classified and shown

MarkerMeaningWhere the line appearsColor
+AddedOnly in the new (changed) textGreen
-RemovedOnly in the original textRed
(space)UnchangedIn both texts, in the same relative orderPlain

What the comparison options do

OptionEffect on matchingEffect on what is displayed
Ignore leading/trailing spacesLines that differ only in surrounding whitespace count as equalNone; original spacing is still shown
Ignore caseUppercase and lowercase versions of a line count as equalNone; original casing is still shown
Both off (default)Lines must match exactly, character for characterEvery line shown exactly as pasted

Common mistakes to avoid

  • Expecting a word-level or character-level diff. This tool compares whole lines. If you change one word in a long line, the whole line shows as one removed line plus one added line, not just the changed word. For prose, put one sentence per line to get finer-grained results.
  • Confusing added and removed direction. Added means a line is in the right box (new) but not the left (original). Removed means it is in the left but not the right. If the results look backwards, you likely pasted the versions in the wrong boxes; use Swap sides to flip them.
  • Trailing whitespace flagging lines as different. A stray trailing space or different indentation makes two otherwise identical lines count as changed. If that is not what you want, tick Ignore leading/trailing spaces so only the visible content is compared.
  • Assuming reordered lines are treated as unchanged. A line-based diff respects order. If you move a block of lines up or down, the diff reports the moved lines as removed from their old spot and added at the new spot, because a subsequence cannot reorder its elements.

Glossary

Diff
The set of differences between two versions of a text, usually shown as added, removed, and unchanged lines.
Line-based diff
A comparison that treats each line as an indivisible unit, marking whole lines as added, removed, or unchanged.
Longest common subsequence (LCS)
The longest ordered set of lines that appears in both texts; it forms the unchanged backbone of the diff.
Subsequence
Any sequence obtained by deleting some elements from a list without changing the order of the elements that remain.
Added line
A line present in the new (changed) text but not in the original, shown in green with a plus sign.
Removed line
A line present in the original text but not in the new version, shown in red with a minus sign.
Unified diff
A common format that lists removed, added, and unchanged lines together in reading order, which is what the Copy diff button produces.

Frequently asked questions

What does a diff checker do?

A diff checker compares two blocks of text and highlights the differences. It marks lines that were added in the new version, lines that were removed from the original, and leaves matching lines unchanged, so you can see exactly what changed at a glance.

How does this tool compare the two texts?

It splits both texts into lines and finds their longest common subsequence, the longest ordered set of lines that appears in both. Those shared lines are treated as unchanged; anything only in the original is marked removed, and anything only in the new text is marked added. This is the same core approach Git and most diff tools use.

Does it compare word by word or line by line?

Line by line. Each line is compared as a whole unit. If you change a single word inside a long line, that line is reported as one removed line and one added line. For finer results, put one sentence or clause on its own line.

What is the difference between added and removed?

Added lines (green, marked with +) exist in the new text on the right but not in the original on the left. Removed lines (red, marked with -) exist in the original but not in the new text. Use Swap sides if you pasted the two versions in the wrong order.

Can it ignore whitespace or capitalization?

Yes. Tick Ignore leading/trailing spaces to treat lines that differ only in surrounding whitespace as equal, and tick Ignore case to treat uppercase and lowercase as the same. These options change only how lines are matched; the text is always displayed exactly as you pasted it.

Is my text uploaded to a server?

No. All comparison happens locally in your browser using plain JavaScript. Nothing you paste leaves your device, which makes it safe to compare private documents, code, or personal data.

Why does moving a block of lines show as removed and added?

A line-based diff preserves order, so moved lines cannot be matched in their new position. They are reported as removed from the old location and added at the new one. This is expected behavior for any subsequence-based diff.

Can I compare two files, not just typed text?

Open each file, copy its contents, and paste one into each box. The tool works on any plain text you paste, including code, CSV rows, logs, and lists.