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.
Minify HTML online by removing comments and extra whitespace safely — free HTML minifier.
About
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.
Examples
4 worked examples
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.
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.
Minify <pre> keep this </pre> and it comes back exactly as <pre> keep this </pre>, since whitespace inside <pre> is preserved exactly.
<p> hi there </p> becomes <p>hi there</p> and the comment <!-- note --> disappears, while <pre> a b </pre> stays exactly as written.
FAQ
Quick answers to common questions about the HTML Minifier.
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.
Yes. It's free, with no sign-up and no limit on how much code you minify.
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.
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.
No. Minification runs entirely in your browser after html-minifier-terser loads from this site — your code never leaves your device.
Yes — switch the language dropdown, or use the dedicated JavaScript minifier or CSS minifier page.
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.
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>.
Yes, the Download button saves it, and the size panel shows the original size, the minified size and how much was saved.
Did HTML Minifier work for you?