HTML Minifier and Beautifier
Compress or format HTML without joining words together — inline elements and pre blocks are left intact.
Processed on your device — no upload
Whitespace between inline elements is a word gap, and deleting it joins words together. That is why the aggressive option is off by default and never touches a boundary where either side is an inline element. The contents of pre, textarea, script and style are passed through untouched.
How to use it
- Paste your markup.
- Choose minify or beautify.
- Check the result, then copy.
How it works
HTML whitespace is not decoration. Any run of spaces and newlines between two pieces of text collapses to a single space when the page renders — and that single space is a real, visible word gap.
This is why aggressive HTML minifiers break pages. Take Roasted <strong>last week</strong> with a newline before the <strong>. Delete that whitespace and the page reads Roastedlast week. It happens on exactly the markup people indent most carefully, and it is invisible in the source afterwards.
The default here collapses each run of whitespace to a single space — safe everywhere, and it still removes the bulk of the bytes — and never deletes it entirely. The aggressive option does delete it, but only where both sides are block-level elements. Where either side is inline, the space is a word gap and it stays.
The contents of pre, textarea, script and style are passed through byte for byte. In the first two, whitespace is displayed as written. In the last two, it is code — and a minifier that reformats JavaScript with automatic semicolon insertion in play is a minifier that introduces bugs.
Conditional comments — <!--[if IE]> — are kept even when comments are removed, because the markup inside them is not a comment at all.
A worked example
Load the sample and minify it with the aggressive option off. Look at the paragraph: the space before <strong> survives, so it still reads "Roasted last week in Amman". Now turn the aggressive option on. The whitespace between <li> elements disappears — correct, they are block-level — but the paragraph is still intact, because strong and em are on the inline list.
And check the pre block. Its indentation is exactly as it was in both modes. That is the test a lot of online minifiers fail, and it is the one that turns a code sample on a documentation page into a single unreadable line.
Beautifying is what most people arrive needing. You have server output, a saved page, or an email template that is one enormous line, and you need to find something in it. Indenting by nesting depth makes the structure visible — and void elements such as <img> and <br> are correctly not treated as opening a level, which is what makes naive indenters drift steadily to the right.
How much is it worth? Less than you would hope. HTML gzips extremely well, because it is full of repeated tag names, so minified and unminified markup often differ by very little over the wire. The real wins on a page are compression, image sizes and fewer render-blocking requests. This is a tidying tool, not a performance strategy.
For the stylesheet, use the CSS minifier; to escape markup so it displays as text rather than rendering, the entity encoder.
Questions
Will minifying break my page?
The default will not — it never deletes whitespace, only collapses each run to a single space. The aggressive option deletes it between block-level tags only, and is off by default.
Why is whitespace between tags significant?
Because between inline elements it renders as a word gap. Deleting it joins two words together, and inline-block elements lose the gap that was holding them apart.
What happens to my pre blocks and scripts?
They are copied through untouched. Whitespace is displayed in pre and textarea, and reformatting JavaScript risks changing what it does.
Are comments removed?
Yes by default, except conditional comments, whose contents are real markup rather than a note.
How much smaller does HTML get?
Usually 10–20% raw, and much less after gzip, since compression already handles repeated whitespace. Do it for tidiness rather than for speed.
Does the beautifier fix broken markup?
No. It indents what it is given. An unclosed tag will make the indentation drift, which is often how you find it.
Can I minify a whole page including the doctype?
Yes. The doctype and any processing instructions are treated as self-contained and left in place.
Is my HTML uploaded?
No. Everything happens in this page, which matters when the markup is an unreleased page or a client’s template.
Related Web tools
Color Converter
HEX, RGB, HSL, HSV, CMYK
open$termiva contrast --wcagColor Contrast Checker
WCAG AA and AAA, with a fix
open$termiva palette --triadicColor Palette Generator
Harmonies and a full tint scale
open$termiva gradient --linearCSS Gradient Generator
Linear, radial and conic
open