HTML Minifier

Minify HTML online by removing comments and extra whitespace safely — free HTML minifier.

About

About the HTML Minifier

Paste HTML and get it minified using html-minifier-terser, a purpose-built HTML minifier that strips comments and collapses insignificant whitespace between tags, while leaving content inside <pre>, <textarea> and <script> exactly as written, since whitespace there is often meaningful.

html-minifier-terser runs here with whitespace collapsing, comment removal, the short doctype and removal of redundant attributes such as type="text/javascript" on scripts. Inline <script> and <style> contents are left as they are, so run those through the JavaScript and CSS minifiers if you want them smaller too.

Choose what to view about this tool

Guide

Using the HTML Minifier

  1. 1

    Step 1

    HTML is already selected below as the language.

  2. 2

    Step 2

    Paste your HTML code into the input box.

  3. 3

    Step 3

    Click Minify to see the compressed output, entirely in your browser.

  4. 4

    Step 4

    Copy the minified code, and check the size reduction shown below the output.

  • Collapses whitespace between tags and removes HTML comments
  • Shortens the doctype to <!doctype html> and drops redundant attributes
  • Leaves <pre> and <textarea> content exactly as written
  • Shows the original size, the minified size and the percentage saved
  • Copy the result or download it as a file
  • Runs in your browser — free, no sign-up, and your code is never uploaded

Static site authors

Authors shrink hand-written pages before uploading them.

Email developers

Developers trim templates so Gmail doesn't clip messages over about 102 KB.

Landing-page builders

Marketers compress exported landing pages for faster loads.

Students

Students see which parts of HTML are safe to remove.

Minify another language

Examples

HTML Minifier examples

4 worked examples

01

Comment stripped

Minify <!-- header --><div class="box"> Hi </div> to get <div class="box">Hi</div> — the comment is removed and the whitespace around the text trimmed.

02

Whitespace between tags

Minify a <ul> with each <li> on its own indented line to get <ul><li>A</li><li>B</li></ul> — the line breaks and indentation between tags are removed.

03

<pre> left untouched

Minify <pre> keep this </pre> and it comes back exactly as <pre> keep this </pre>, since whitespace inside <pre> is preserved exactly.

04

What changes and what doesn't

<p> hi there </p> becomes <p>hi there</p> and the comment <!-- note --> disappears, while <pre> a b </pre> stays exactly as written.

FAQ

Frequently asked questions

Quick answers to common questions about the HTML Minifier.

How do I minify HTML?

Paste your HTML code above, make sure HTML is selected, then click Minify. The minified output appears in the box below it — everything runs in your browser, using html-minifier-terser.

Is this HTML minifier free?

Yes. It's free, with no sign-up and no limit on how much code you minify.

Will it break whitespace-sensitive tags like <pre> or <textarea>?

No — html-minifier-terser is built specifically to leave content inside <pre>, <textarea> and <script> blocks untouched, since collapsing whitespace there would change what's actually displayed.

Does it minify inline <script> and <style> blocks too?

No. The markup around them is minified, but the code inside <script> and <style> tags is kept as written, apart from trimming the blank space at its start and end. Run that code through the JavaScript Minifier or CSS Minifier separately, then paste it back in.

Is my HTML uploaded anywhere?

No. Minification runs entirely in your browser after html-minifier-terser loads from this site — your code never leaves your device.

Can I minify JavaScript or CSS here too?

Yes — switch the language dropdown, or use the dedicated JavaScript minifier or CSS minifier page.

Does it remove attribute quotes or optional closing tags?

No. Attribute quotes and optional closing tags such as </li> are kept, which keeps the output safe and easy to read back. It focuses on comments, whitespace and redundant attributes.

What counts as a redundant attribute?

One that only repeats the browser's default, such as type="text/javascript" on a script tag or type="text" on an input. They're removed because the page behaves the same without them, and the doctype is shortened to <!doctype html>.

Can I download the minified HTML?

Yes, the Download button saves it, and the size panel shows the original size, the minified size and how much was saved.

Still have a question? Contact us

Report a problem

HTML Minifier

What went wrong?
    or paste a screenshot