Code Diff Checker
Paste or open two versions of a file to see exactly what changed. Lines are matched with the Myers diff algorithm, changed words inside each line are highlighted, and the code is syntax colored for JavaScript, Python, HTML, CSS, SQL and more.
How to use the Code Diff Checker
- Paste the original code on the left and the changed version on the right, or press Open file above each box.
- Choose the language or leave Auto-detect on, and tick Ignore whitespace or Ignore case if formatting changes should not count.
- Press Compare code. Removed lines are red, added lines green, and the exact changed words are highlighted darker.
- Switch views between Side by side and Unified, and use Prev / Next to jump between changes. Click a gray bar to reveal hidden unchanged lines.
- Download .diff or copy the unified diff to share the change or apply it with git apply or patch.
Reading the diff
| You see | Meaning |
|---|---|
| Red line with − | Line exists only in the original (removed) |
| Green line with + | Line exists only in the changed version (added) |
| Red and green line side by side | Line was modified; darker highlights mark the exact words that changed |
| Striped empty cell | Nothing on that side: a pure insertion or deletion |
| Gray "⋯ 12 unchanged lines" bar | Identical lines hidden to keep the focus on changes; click to expand |
A worked example
Comparing this original:
const TAX = 0.2; const total = price * (1 + TAX);
with this changed version:
const TAX = 0.21; const total = price * (1 + TAX); console.log(total);
gives 1 modified line (0.2 → 0.21 is highlighted inside it), 1 added line and no pure deletions: +2 −1. Similarity is calculated as 2 × unchanged lines ÷ (lines in original + lines in changed) × 100 = 2 × 1 ÷ (2 + 3) × 100 = 40%. The unified diff is:
--- original +++ changed @@ -1,2 +1,3 @@ -const TAX = 0.2; +const TAX = 0.21; const total = price * (1 + TAX); +console.log(total);
Tips for cleaner code comparisons
- Format both sides the same way first. Run each version through a formatter (Prettier, Black, gofmt, or the beautifier tools on this site) so style changes do not hide real ones.
- Turn on Ignore whitespace when indentation changed, for example after wrapping code in a new block.
- Compare minified files after beautifying them. A minified file is often a single line, so any change marks the whole file as different.
- Use the .diff file with
git apply changes.difforpatch -p0 < changes.diffto apply the same change elsewhere (edit the file names in the --- and +++ lines to match your paths).
Frequently asked questions
How does the code diff checker find changes?
It splits both texts into lines and runs the Myers O(ND) difference algorithm, the same approach used by git and GNU diff, to find the longest common subsequence of lines. Lines that are removed and added in the same place are paired, and a second word-level comparison highlights exactly what changed inside them.
Is my code uploaded anywhere?
No. The comparison and syntax highlighting run entirely in your browser with JavaScript. Files you open are read locally and are never sent to a server, so it is safe for private or proprietary code.
What does Ignore whitespace do?
It collapses runs of spaces and tabs and ignores leading and trailing whitespace when matching lines, so re-indented code or trailing spaces do not show up as changes. The display still shows your original text.
What is a unified diff?
It is the standard text format for changes used by git, patch and code review tools. Lines starting with - were removed, lines starting with + were added, and @@ -10,7 +10,8 @@ headers say where each block of changes starts and how many lines it covers in the old and new file.
Which languages are highlighted?
JavaScript and TypeScript, Python, Java and Kotlin, C and C++, C#, Go, Rust, PHP, Ruby, HTML and XML, CSS and SCSS, JSON, SQL, Shell and YAML. Keywords, strings, comments and numbers are colored. Auto-detect picks a language from the code, or from the file extension when you open a file.
How large can the files be?
Up to 20,000 lines per side. Very different files are still compared, but if the number of changes is extremely large the changed region is shown as a full replacement to keep the page responsive.