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
- Paste your HTML into Input HTML.
- Press Format or Minify.
- 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
- Reading HTML copied from a page source or an email template.
- Tidying generated markup before a code review.
- Shrinking a small snippet.
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
- Drifting indentation. An element that opens and closes on one line, such as
<li>One</li>, is counted as opening, so what follows can be indented one level too deep. In<div><p>Hi</p></div>the closing</div>ends up indented under the<p>. The markup is unchanged, but treat the indentation as a visual aid, not proof of structure. - Preformatted text. Minify turns the newlines and indentation inside
<pre>into single spaces, so<pre>a<newline> b</pre>becomes<pre>a b</pre>. Never minify markup containing code samples with this tool. - Inline spacing. Collapsing a run of spaces to one is harmless in normal text, but it changes layouts that used several literal spaces. Entities such as
are left alone. - Attributes are never wrapped or reordered, so a long tag stays on one long line.
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.