HTML Formatter
Indent messy HTML, or minify it for production.
Whitespace inside pre, textarea, script and style is preserved exactly.
About this tool
Re-indent HTML that has lost its shape, or strip it down for production. Void elements like img and br are handled correctly, and pre blocks keep their whitespace instead of being reflowed.
How to use it
- Paste your markup.
- Choose Format with an indent width, or Minify.
- Copy or download the result.
Where whitespace actually matters in HTML
HTML collapses runs of whitespace to a single space when rendering, which is why you can indent markup freely. There are exceptions, and a formatter that ignores them will change how your page looks.
<pre> and <textarea> preserve whitespace exactly. Re-indenting their contents changes what the user sees. Both are passed through untouched here.
<script> and <style> contain code, not markup. Their contents are copied verbatim rather than parsed as HTML.
Inline elements are whitespace-sensitive at their boundaries. This:
<p>Read the <a href="/docs">docs</a> first.</p>
renders differently if a newline is inserted before </a>, because that whitespace becomes a rendered space. This is why aggressive minifiers can push punctuation onto the wrong side of a link.
What minification here does and does not do
Minification removes comments and collapses whitespace between tags. That is all — deliberately.
What it will not do:
- Remove optional closing tags such as
</li>and</p>. Legal HTML, but it makes the source much harder to reason about and breaks some downstream parsers. - Strip quotes from attribute values. Legal for simple values, a silent bug for anything containing a space.
- Reorder or deduplicate attributes.
- Inline or minify CSS and JavaScript inside the document. Use the CSS & JS minifier for those.
For a production build you want a full pipeline that also inlines critical CSS and defers scripts. This is for the case where you have a snippet, an email template, or a page you want to shrink quickly without setting any of that up.
Frequently asked questions
- Is the content inside pre and textarea preserved?
- Yes. Whitespace is significant in those elements, so their contents are passed through untouched rather than re-indented.
- How aggressive is minification?
- It removes comments and collapses runs of whitespace between tags. It does not rewrite attributes or strip optional closing tags, so the output stays safe to ship.
- Is my markup uploaded?
- No. The formatter is plain JavaScript running in your browser, so unreleased page templates and markup stay private.