CompareOnline4U.

Home › Guides

How to compare two HTML files and find what changed

HTML Compare — open the free tool →

Comparing two HTML files sounds easy until one of them is minified. A build tool or CMS outputs the whole page as a single line, the other version is hand-formatted, and a normal diff reports that everything changed. The same thing happens when two tools indent differently or write attributes in a different order.

As with XML, the trick is to format both sides the same way first, then compare. Here are four ways to do it.

What makes HTML hard to diff

Method 1: Compare HTML online (fastest)

  1. Open HTML Compare.
  2. Paste the original HTML on the left and the changed HTML on the right. A full page source or a small snippet both work.
  3. Leave Format HTML ticked. Both sides are laid out with one tag per line and the same indentation.
  4. Tick Sort attributes if the two versions come from different tools.
  5. Click Compare now, then use Next change to jump through changed tags, attributes and text.

The markup is compared as text in your browser: it is not rendered, scripts are not run and nothing is uploaded.

Good to know: the formatter reads HTML the way a browser does, so a missing closing tag such as an unclosed <p> is filled in. If you are hunting for exactly that kind of source error, untick Format HTML and compare the raw text.

Method 2: VS Code

  1. Open both files and run Format Document (Shift+Alt+F on Windows, Shift+Option+F on macOS) on each one. VS Code has a built-in HTML formatter.
  2. In the Explorer, select both files, right-click and choose Compare Selected, or run code --diff old.html new.html in a terminal.

Good for: files that are already part of a project, especially when you want to edit while you compare.

Method 3: Command line with Prettier and diff

If Node.js is installed, Prettier can format both files identically before a normal diff:

npx prettier old.html > old.fmt.html
npx prettier new.html > new.fmt.html
diff -u old.fmt.html new.fmt.html

Inside a Git repository, git diff --word-diff is also useful for long lines, because it marks changed words instead of whole lines.

Good for: scripts, CI checks and comparing many files.

Method 4: Compare the rendered pages

Sometimes the question is not "what changed in the code" but "what looks different". Take a screenshot of each version at the same browser width, then compare them in Image Compare and turn on Highlight differences in red. This catches layout shifts that are hard to see in markup, such as a CSS change.

Which method should you use?

Tips for a clean HTML comparison

HTML Compare — open the free tool →

Frequently asked questions

Why does my HTML diff show the whole file as changed?

One side is probably minified (the whole page on one line) or uses different indentation. Format both sides the same way first; the online HTML Compare does this automatically when Format HTML is ticked.

Does attribute order matter in HTML?

No. <a class="btn" href="/"> and <a href="/" class="btn"> mean the same thing. Tick Sort attributes in HTML Compare so a different attribute order is not reported as a change.

How do I compare two live web pages?

Open View Source (Ctrl+U) on each page, copy the source into the two sides of HTML Compare and compare. Source from View Source is the HTML the server sent; content added later by JavaScript is not included.

Can I see visual differences instead of code differences?

Yes. Take a screenshot of each page at the same window size and compare the two images with Image Compare, which can highlight the changed pixels in red.

More guides

How to compare two XML files and find the differencesCompare two XML files the right way: format both first, handle attribute order, then diff online, in Notepad++, VS Code or with xmllint on the command line.How to find differences between two textsSpot every change between two versions of a text — essays, emails, contract clauses or notes. Free diff checker guide with tips to avoid false changes.How to compare two Word documents and find every changeGot a revised Word file without tracked changes? Learn 3 ways to compare two .docx documents, including a free online method that keeps files private.How to compare two PDF files for differencesFind what changed between two PDF versions of a contract, invoice or report. Step-by-step free method, plus what to do with scanned PDFs.

← All comparison tools