HTML Formatter & Minifier

Make cramped HTML readable, or compress readable HTML for delivery.

Format and minify

Format indents nested elements so the structure is visible. Minify removes extra whitespace to shorten the markup.

Tips

Check the result in your browser after minifying, especially around inline text and preformatted blocks where whitespace can matter.

How to use it

  1. Paste your HTML into Input HTML.
  2. Press Format or Minify.
  3. Copy the Output.

Example

This snippet:

<div><p>Hello <b>World</b></p></div>

is split so that each tag pair starts on its own line, indented by nesting depth, while the text stays on the same line as its element, as in <p>Hello <b>World</b></p>.

Common use cases

What Format and Minify really do

Format first inserts a line break between every pair of adjacent tags, then indents by nesting depth using two spaces. Void elements such as <br>, <img> and <input>, tags ending in />, and anything starting with <! (doctype and comments) do not increase the depth. Text between tags stays on the same line as its element, so <p>Hi <b>there</b></p> is not broken up.

Minify removes whitespace between tags and collapses any run of two or more whitespace characters into one space. It does not remove comments, shorten attributes or touch the contents of <script> and <style>, so the savings are modest.

Where the output can surprise you

Good uses and better alternatives

The best use is reading: paste a block from view-source or an email template and press Format to see how it nests. For code you own, an editor formatter or Prettier is more accurate because it understands inline versus block elements, preserves <pre> and handles embedded scripts. For production minification, use html-minifier-terser or your framework's build step, which can safely remove comments and optional tags.

After any minify, load the result in a browser and compare it with the original, paying attention to spacing between inline elements and anything inside <pre> or <textarea>.

Frequently asked questions

What does an HTML formatter do?

It adds line breaks and indentation so nested elements are easy to follow.

Will minifying break my page?

It can. Minify collapses whitespace everywhere, including inside pre blocks and textareas, and it changes spacing between inline elements. Always load the result in a browser and compare.

Does it validate my HTML?

No, it formats the markup you give it; indentation can even drift on lines that open and close an element.

Is my data uploaded?

No. This tool runs entirely in your browser, so what you type or paste is not sent to our servers.

Why is my closing tag indented too far?

The formatter counts any element that starts on a line as opening, even if it closes on the same line, so the depth can drift. The HTML itself is not changed.

Does minify remove comments?

No. It only removes whitespace between tags and collapses repeated spaces. Strip comments yourself if you want them gone.

Related tools

Explore all developer tools →