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
- Minified markup:
<ul><li>One</li><li>Two</li></ul>on one line and the same list spread over four lines are identical to a browser, but not to a line diff. - Attribute order:
<img alt="Logo" src="logo.png">and<img src="logo.png" alt="Logo">are equivalent. - Whitespace between tags is mostly ignored by browsers, but inside
<pre>and<textarea>it matters.
Method 1: Compare HTML online (fastest)
- Open HTML Compare.
- Paste the original HTML on the left and the changed HTML on the right. A full page source or a small snippet both work.
- Leave Format HTML ticked. Both sides are laid out with one tag per line and the same indentation.
- Tick Sort attributes if the two versions come from different tools.
- 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
- 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.
- In the Explorer, select both files, right-click and choose Compare Selected, or run
code --diff old.html new.htmlin 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?
- Two snippets, email templates or page sources: online HTML Compare.
- Files in a code project: VS Code or
git diff. - Automation: Prettier + diff.
- Visual changes: screenshots + Image Compare.
Tips for a clean HTML comparison
- To check SEO changes only, paste just the
<head>of each page: titles, meta descriptions, canonicals and structured data are all there. - Strip values that change on every page load (CSRF tokens, nonces, cache-busting query strings) if you only care about real edits.
- Comparing XML or JSON instead? Use XML Compare or JSON Compare; for program code use Code Compare.
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.