HTML Minifier

Compress HTML without changing how it renders.

Input
HTML input
Output
Result
Options

About this tool


Minifying HTML removes whitespace and comments to reduce page weight. The difficulty is that HTML whitespace is not uniformly insignificant, removing the wrong space changes what the page looks like.

This minifier is deliberately conservative. It collapses whitespace between block elements, where it has no effect, and preserves a single space between inline elements, where it renders as a visible gap.

How to use it

  1. Paste or upload your htmlDrop a file onto the input pane, use the file picker, or paste the text directly.
  2. Adjust the options if neededThe defaults suit most input; open Options to change the behaviour.
  3. MinifyPress Minify, or use Ctrl+Enter (Cmd+Enter on macOS).
  4. Copy or downloadCopy the result, or download it as a .html file.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

Block whitespace removed, inline space kept

Input

<div>
  <p>Hello <b>there</b> <i>friend</i></p>
</div>

Output

<div><p>Hello <b>there</b> <i>friend</i></p></div>

Indentation between the div and p is gone; the spaces around the inline elements remain.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

Why whitespace between inline elements is kept
The markup <b>a</b> <i>b</i> renders as "a b". Remove that space and it becomes "ab", the words run together. Aggressive minifiers that strip it produce exactly this bug. Space between block-level elements has no rendered effect and is removed.
Protected regions
Content inside <pre>, <textarea>, <script> and <style> is left untouched. Collapsing whitespace in a <pre> would alter the display, and altering script or style content risks breaking it.
Conditional comments survive
Ordinary comments are removed, but conditional comments beginning <!--[if are preserved, because they carry instructions for legacy Internet Explorer rather than being documentation.
Minification versus compression
Gzip and Brotli already compress repeated whitespace efficiently, so minifying a compressed response yields a much smaller saving than the raw character count suggests. The benefit is clearest for HTML inlined into another document, stored uncompressed, or served without compression.

Limitations


  • Does not minify embedded JavaScript or CSS.
  • Does not remove optional closing tags or redundant attributes, which risk changing behaviour.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


Could minifying break my layout?
This minifier preserves whitespace where it is rendered, between inline elements and inside pre, so the risk is low. Aggressive minifiers that strip all whitespace can and do cause text to run together.
Is it worth minifying if my server gzips?
The additional saving is modest, since gzip handles repeated whitespace well. It is most useful for HTML embedded in another file or served uncompressed.