b2KIT

Code Diff Viewer

Compare two code blocks with syntax-highlighted side-by-side and unified diff views.

Tested tool guide Text and writing tools Checked July 30, 2026

What Code Diff Viewer does, with a checked example

The diff viewer identifies unchanged, inserted, and removed lines and can display the result in unified or split form. It uses a longest common subsequence table to find an ordered set of lines shared by both inputs. This favors a readable line-level comparison without pretending to understand programming-language syntax.

Worked example

A concrete input and expected output from the current implementation.

Input

Original:
const mode = "light";
start();

Modified:
const mode = "dark";
start();

Expected output

- const mode = "light";
+ const mode = "dark";
  start();

The changed assignment is represented as one removed line and one added line. The call to start remains unchanged.

How the result is produced

1

Matching lines must be exactly equal

Spaces, tabs, letter case, and line endings inside the split text can affect equality. The algorithm does not ignore formatting differences unless you normalize the inputs first.

2

The comparison is line based

A one-character edit marks the complete line as removed and added. Character-level highlighting and language-aware refactoring detection are outside this viewer.

Good uses

  • Review a small configuration change before applying it.
  • Compare copied command output from two environments.
  • Create a unified text summary for a discussion.

Limits and checks

  • Large files require quadratic memory in this implementation.
  • Moved blocks may appear as a deletion plus an insertion.
  • A visual diff does not validate that either version is correct or safe.

Common questions

Why is a changed line shown twice?

Line-level diff represents replacement as removal of the old line and insertion of the new line. That preserves both exact versions.

Does split view calculate a different result?

No. Unified and split views present the same computed sequence in different layouts.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools