Skip to content
Devtoolry

HTML Minifier

Minify HTML online: remove comments and collapse whitespace while keeping pre, textarea, script and style blocks intact. See the size saved instantly.

Runs in your browser · Nothing uploadedFree · No sign-up

Something not working, or missing a feature? Send feedback

About the HTML Minifier

The HTML Minifier shrinks pages by removing comments and collapsing whitespace, while leaving <pre>, <textarea>, <script> and <style> blocks untouched so nothing breaks.

Everything runs in your browser, so your input is never uploaded to a server.

How to use the HTML Minifier

  1. Paste HTML or open a file.
  2. Choose whether to remove comments.
  3. Copy or download the minified markup.

Example

Shrink a page fragment

Input

<!-- Card component -->
<div class="card">
    <h2>  Pricing  </h2>
    <p>
        Start free, upgrade any time.
    </p>
    <pre>  keep   this   spacing  </pre>
</div>

Result

<div class="card"><h2> Pricing </h2><p> Start free, upgrade any time. </p> <pre>  keep   this   spacing  </pre> </div>

The comment is removed and runs of whitespace collapse to one space, but the <pre> block keeps its spacing exactly.

Common mistakes

  • Removing conditional or licence comments. Some comments matter, such as licence notices or server-side include markers. Switch off "Remove comments" when a page relies on them.
  • Inline elements losing their space. Whitespace between inline elements, as in <b>Hello</b> <i>world</i>, is collapsed to one space but never removed, so words do not run together.
  • Minifying templates. Template syntax such as {{ }} or <?php ?> is treated as text. Minify the rendered HTML instead of the template if the result looks wrong.

Works well with the HTML Minifier

Frequently asked questions

Why are <pre> and <textarea> left alone?

Whitespace inside them is displayed to the user, so collapsing it would change the page.

Can I keep comments?

Yes. Switch off "Remove comments" to keep them, for example licence notices.

Are inline scripts and styles minified?

No. <script> and <style> blocks are kept as they are, so they cannot break. Minify them separately with the JavaScript and CSS minifiers.

How much smaller will my page be?

Typically 5–20% before compression, depending on how much indentation and how many comments the markup has. The saving is shown below the output.

Guides and tutorials