HTML Formatter & Beautifier

Paste messy or minified HTML to beautify it with 2 spaces, 4 spaces or tabs, or minify it for production. Only whitespace changes, so the page renders exactly the same.

Ctrl+Enter also works. Only whitespace changes: the page renders the same.

Want to see the page itself? Paste the result into the HTML viewer to preview it at desktop, tablet or phone width.

Beautify

Indent messy or minified HTML with 2 spaces, 4 spaces or tabs, one element per line, so the structure is visible at a glance.

Minify

Collapse whitespace and drop comments for production, without gluing words together or touching pre, textarea, script and style.

Same rendering

Only whitespace changes. The engine is checked against w3.org, MDN, gov.uk, php.net, Bootstrap and Wikipedia.

A Formatter That Does Not Change Your Page

Whitespace in HTML is not always decoration. A space between two inline elements is a visible space, a line break inside a paragraph separates two words, and inside <pre> or <textarea> every character counts. A beautifier or minifier that treats all whitespace as noise produces code that looks tidy and renders differently:

InputCareless formattingWhat the page shows
<b>Save</b> <i>now</i><b>Save</b><i>now</i>"Savenow" instead of "Save now"
<p>hello world</p><p>helloworld</p>Two words glued into one
class="card active"class="cardactive"Neither class applies any more
<button>A</button><button>B</button>One button per lineA gap appears between the buttons

This formatter collapses a run of whitespace to a single space instead of deleting it, keeps form controls and images on the line they share, leaves <pre> and <textarea> untouched, keeps entities such as &nbsp; encoded and keeps conditional comments. Each change to the engine is tested by parsing the page before and after with the same HTML parser browsers use, and comparing what would be displayed.

How Much Does Minifying HTML Save?

It depends on how the page was written. Measured with this minifier on the home pages of well-known sites, before compression:

PageBeforeAfterSaved
developer.mozilla.org119 KB75 KB37%
w3.org49 KB42 KB14%
gov.uk84 KB74 KB12%
php.net53 KB48 KB9%

Measured on 12 October 2026. Gzip or Brotli compression on the server narrows the gap, because repeated whitespace compresses well, so minifying matters most for HTML that is inlined, sent in an email, or served without compression.

Formatting Shows Errors, It Does Not Fix Them

Indenting HTML is the quickest way to see its structure: a closing tag that lands at the wrong depth usually means an element was never closed, or was closed in the wrong order. The formatter keeps your markup as written, so it will not repair those mistakes. Paste the result into the HTML validator to get each error with its line, and see how to find unclosed tags and fix incorrect nesting.

HTML Indentation: 2 Spaces, 4 Spaces or Tabs

2 spaces

The most common choice in front-end projects and the default of Prettier. Deep trees stay readable on a narrow screen.

<div>
  <p>
    Hello
  </p>
</div>

4 spaces

Common in back-end templates and older codebases. More separation between levels, at the cost of width.

<div>
    <p>
        Hello
    </p>
</div>

Tabs

Each reader sets the width they like in their editor, which is why some teams prefer them for accessibility.

<div>
	<p>
		Hello
	</p>
</div>

Whatever you pick, use what your repository already uses: mixed indentation makes every diff noisier than the change it contains.

Frequently Asked Questions

What does an HTML formatter do?
An HTML formatter, also called an HTML beautifier or prettifier, rewrites the whitespace of your markup: one element per line and consistent indentation, so the nesting is easy to follow. It changes how the code reads, not what it contains.
Does formatting change how my page renders?
Not with this tool, by design: it only changes whitespace and keeps every space that is visible. The contents of pre and textarea are left exactly as they are. In minify mode comments are removed, except conditional comments. If you tick the option to minify inline CSS and JavaScript as well, that code is rewritten too, so test the result.
What is the difference between beautify and minify?
Beautify adds line breaks and indentation so people can read the code. Minify removes what a browser does not need, so the file is smaller. Keep the beautified version in your repository and minify at build time, or before you paste HTML somewhere size matters.
Can it fix broken HTML?
No. It formats your markup as written, so an unclosed tag stays unclosed, though the indentation usually makes it obvious. Use the HTML validator to find each error with its line number.
Is my HTML stored?
No. The HTML is sent to our server to be formatted and the result is returned to you. It is not logged, stored or added to any history.
Is there a size limit?
Up to 2 MB of HTML per run, which covers a full page with inline styles and scripts. Very large documents can take a second or two.
Can I format JSON, CSS or XML here?
This page is for HTML. JSON has its own formatter, which keeps every number exactly as written, and CSS and XML each have a validator.

Related Tools