Skip to content
ToolZone

Code Diff

Diff two code snippets with syntax awareness, highlighting exactly what changed between versions, useful for reviewing edits before merging.

Runs in your browser. Nothing you enter or upload leaves your device.

Original
Modified
Differences
Paste text in both boxes to compare

Keyboard shortcuts

Run the main action
⌘ / Ctrl + Enter
Copy the result
⌘ / Ctrl + Shift + Enter
Download the result
⌘ / Ctrl + S
Paste a file or image into file tools
⌘ / Ctrl + V
Search all tools
⌘ / Ctrl + K
Show these shortcuts
?

You can also drop files anywhere on the page.

About the Code Diff

Code Diff is a quick way to compare two versions of a function, config block, or script without committing anything to a repository. Paste the old and new code, and the tool lists every line that was kept, removed, or added.

How it works

Code Diff uses the same engine as the site's Text Diff tool. Both texts are split into lines and aligned with a longest-common-subsequence algorithm, the same idea behind git diff. It finds the largest set of lines the two versions share in order, so an inserted or deleted line shows up as a single change and the lines after it still match.

Within a block of changes, each removed line is paired with an added line and compared word by word, and the exact words that changed are highlighted. Options let you ignore whitespace or letter case, show only the changed lines with two lines of context, and switch between side-by-side and unified views.

How to use

  1. 1

    Paste or open the earlier version in Original, and the newer one in Modified.

  2. 2

    Read the result: removed lines in red, added lines in green, with changed words highlighted.

  3. 3

    Switch between Side by side and Unified, or tick Ignore whitespace, Ignore case or Only changes.

  4. 4

    Click Copy diff to copy the result with - and + markers.

Worked examples

A changed return value

Reviewing a one-line fix in a small JavaScript function.

Input
Original: function total(a, b) { return a - b; } Modified: function total(a, b) { return a + b; }
Result
function total(a, b) { - return a - b; + return a + b; }

Only the middle line differs, so it is the only one flagged.

Indentation-only change

A formatter changed two-space indentation to four spaces.

Input
Original: if x: print(x) Modified: if x: print(x)
Result
if x: - print(x) + print(x)

Whitespace is compared exactly, so a pure re-indent is reported as a change.

Limitations
Very large inputs (roughly 2,000 × 2,000 changed lines) fall back to a simpler comparison to stay fast. Moved blocks show as a deletion in one place and an addition in another; moves aren't detected separately. There is no syntax highlighting.
Assumptions
The code is plain text with ordinary line breaks. Both snippets cover the same section of code.
Privacy
Your code is compared in your browser and is not uploaded to a server or stored.

Frequently asked questions

Does this work for any programming language?+

Yes. Code is treated as plain text, so JavaScript, Python, PHP, SQL, YAML, or anything else compares the same way. There is no language-specific highlighting.

How is this different from Text Diff?+

It uses the same engine as Text Diff. The page is aimed at code, but the results are identical to comparing the same content in Text Diff.

Will indentation changes show up?+

By default yes, since spaces and tabs are part of each line. Tick Ignore whitespace to treat re-indented lines as unchanged.

Will lines I didn't touch show as changed?+

It shouldn't any more. Lines are aligned by content, not by position, so an inserted or deleted line shows as one change and the following lines still match.

Is my code sent to a server?+

No. The comparison runs in your browser, so the code you paste stays on your device.

Related tools