Code Diff Checker
Compare two versions of code side by side or inline, with syntax highlighting, line numbers, whitespace options and a unified diff you can copy or download.
How to compare two pieces of code
- Paste the old version in Original code and the new version in Changed code.
- Choose the Language, or leave Detect automatically: the tool guesses from the code and shows the detected language next to the statistics.
- Pick a View: Side by side or Inline (unified).
- Set the options you need: Ignore whitespace and indentation, Ignore case, Highlight changed words and Show only changes (3 lines of context).
- Click Compare. After the first comparison, the result follows your edits as you type.
- Click Copy as unified diff or Download .diff to reuse the change as a patch.
Swap sides exchanges the two versions, which turns additions into deletions and the other way round.
Reading the diff
Removed lines are tinted red and belong to the original; added lines are tinted green and belong to the new version. Every line keeps its line number from its own file, so you can jump straight to it in your editor.
- Side by side puts the two files in two numbered columns. A modified line sits next to its new version. With Highlight changed words, the words that changed inside that line are marked; without it, both lines keep their full syntax colours.
- Inline (unified) shows a single column like a code review: for each changed block, the removed lines (−) come first, then the added lines (+), with both the old and the new line numbers.
- Show only changes (3 lines of context) folds long unchanged stretches into a “⋯ N unchanged lines” marker, which makes big files much easier to review.
The statistics line counts added, removed and unchanged lines.
Syntax highlighting
Highlighting is done in your browser with highlight.js. Only the grammar of the chosen language is loaded, when you first compare, so the page stays light. Supported languages include JavaScript, TypeScript, Python, Java, C#, C / C++, Go, Rust, PHP, Ruby, CSS, HTML / XML, JSON, YAML, SQL, Bash / Shell and Markdown. Automatic detection uses simple clues (keywords, brackets, JSON parsing); if it guesses wrong, choose the language yourself or pick Plain text.
Whitespace, indentation and line endings
Ignore whitespace and indentation compares lines after trimming them and collapsing runs of spaces and tabs, so a file re-indented from 2 to 4 spaces or from tabs to spaces shows no difference. Windows (CRLF) and Unix (LF) line endings are normalised before comparing, so a file that only changed its line endings is reported as identical. Note that whitespace can matter in Python, YAML and Makefiles: turn the option off when indentation is significant.
The unified diff format
The exported patch uses the standard unified format read by git apply, patch and code review tools: a header with the two file names, then hunks starting with @@ -a,b +c,d @@ and three lines of context around each change. The files are named original and changed with an extension for the language.
Frequently asked questions
Is my code uploaded to a server?
No. The comparison and the highlighting both run locally in your browser; the code never leaves your device.
How is this different from the text diff checker?
It uses the same line-by-line comparison engine, but adds syntax highlighting, a unified view, context folding and code-oriented whitespace handling.
Why are two lines shown as changed when they look identical?
They probably differ in invisible characters: trailing spaces, tabs versus spaces, or a non-breaking space. Tick Ignore whitespace and indentation to confirm.
Can I apply the downloaded patch with Git?
Yes. Save it and run patch original.js < changes.diff, or adapt the file names in the header and use git apply.
How large can the snippets be?
Several thousand lines compare quickly. If two very large files are completely different, the tool stops after a few seconds and asks you to compare smaller parts.
Related tools
- Text Diff Checker Compare two texts and see every difference side by side or inline, by line, word or character. Private diff checker that runs in your browser.
- JSON Formatter and Validator Free JSON formatter and validator that beautifies, minifies and checks JSON in your browser, with syntax errors reported by line and column.
- Regex Tester Test JavaScript regular expressions live with highlighted matches, capture groups, replacement and a plain-English explanation of every token.