Home › Developer Tools › Code Diff Checker

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.

Last updated:

Advertisement
Advertisement

How to use the Code Diff Checker

  1. Paste the original code on the left and the changed version on the right, or press Open file above each box.
  2. Choose the language or leave Auto-detect on, and tick Ignore whitespace or Ignore case if formatting changes should not count.
  3. Press Compare code. Removed lines are red, added lines green, and the exact changed words are highlighted darker.
  4. 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.
  5. Download .diff or copy the unified diff to share the change or apply it with git apply or patch.

Reading the diff

You seeMeaning
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 sideLine was modified; darker highlights mark the exact words that changed
Striped empty cellNothing on that side: a pure insertion or deletion
Gray "⋯ 12 unchanged lines" barIdentical 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.diff or patch -p0 < changes.diff to 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.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

JavaScript BeautifierFormat and beautify messy or minified JavaScript, or minify it.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.HTML FormatterBeautify and indent HTML code with a live preview.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.Code Typing TestTyping test with real code in JavaScript, Python, HTML, CSS and more: WPM, accuracy and symbol errors.Compare PDFCompare two PDF files and see added, removed and changed text side by side, page by page.Compare Two ListsFind items only in list A, only in list B, in both lists, or in either, with copy and sort.ES6 to ES5 ConverterTranspile modern JavaScript (ES2015+) to ES5 with Babel: targets, module format and loose mode.CSS FormatterBeautify CSS with indent controls and optional property sorting.XML FormatterBeautify, validate and minify XML with a collapsible tree view.ZIP File CreatorCompress files and folders into a ZIP.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.HTML MinifierMinify HTML: strip comments and whitespace safely and see how many bytes you save.CSS MinifierMinify CSS with csso or a built-in engine and see the size saved instantly.JavaScript MinifierMinify JavaScript with Terser: compress, mangle and see how many bytes you save.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.CSS ValidatorValidate CSS: syntax errors, unknown properties and invalid values by line, plus auto-fix.Gzip Compress / DecompressGzip or deflate text and files, get Base64 output, and decompress Base64 or .gz files.IBAN ValidatorCheck an IBAN's mod-97 checksum, country and length, and see its bank code and account parts.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JSON Schema ValidatorValidate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with clickable error paths.Markdown FormatterBeautify Markdown with Prettier: list markers, prose wrap, aligned tables and live preview.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.TypeScript FormatterFormat TypeScript and TSX code with Prettier: width, tabs, semicolons and quotes options.XML MinifierMinify and validate XML: strip whitespace and comments, keep CDATA, see the size savings.C# FormatterBeautify C# code online: Allman or K&R braces, indent size and line width, clang-format option.HTML ValidatorCheck HTML for errors and warnings with line numbers, locally or with the W3C Nu checker.Java FormatterBeautify Java code online: indent size, brace style and line width, with clang-format option.JavaScript ObfuscatorObfuscate JavaScript with string encoding, renaming and control-flow flattening presets.Phone Number FormatterFormat and validate lists of phone numbers to E.164, international or national style.Python FormatterFormat Python code in Black/Ruff style: line length, quote style, indent, copy or download.Responsive Design CheckerPreview any website at phone, tablet, laptop and desktop sizes side by side, with rotate and zoom.Browser Compatibility CheckerSearch CSS, JavaScript and HTML features and see which browser versions support them.Core Web Vitals CheckerCheck real-user LCP, INP and CLS for any URL or site and see if it passes Core Web Vitals.Heading Structure CheckerPaste HTML to see its H1-H6 outline and catch missing H1s, multiple H1s and skipped levels.Website Hosting CheckerFind out who hosts a website: hosting provider, IP addresses, ASN, network owner and location.Routing Number ValidatorCheck a US ABA routing number's checksum and format and see its Federal Reserve district.XSD ValidatorValidate XML against an XSD schema in your browser and see each error with its line number.Strftime Format BuilderBuild Python and C strftime format strings by clicking tokens, with a live preview and reference.Spam Word CheckerScan an email subject and body for spam trigger words, excess caps, exclamation marks and risky links.Check Digit CalculatorCalculate or validate check digits for UPC, EAN, GTIN, SSCC, ISBN, ISSN and mod 11 codes.Luhn Algorithm CheckerValidate numbers with the Luhn mod 10 check or calculate the missing check digit, step by step.
See all 41 Code Formatters & Validators →