HTML Minifier
Minify HTML without changing how it renders: comments removed, whitespace collapsed, and pre, textarea, script and style copied through untouched.
<div class="card"><h2>Title</h2><p>Some <em>text</em> here.</p></div>
Output is valid and updates as you type.
Fix the highlighted fields to update the output.
Paste markup and get it back smaller, without changing how it renders. Whitespace between inline elements is kept as a single space, and pre, textarea, script and style are copied through byte for byte.
How to use
- Paste the HTML. It stays in this tab.
- Leave “remove whitespace between block elements” on. That is the whitespace that never renders, so removing it is safe.
- Turn it off if you are minifying a fragment whose surroundings you cannot see. Every gap then becomes a single space, which is the most conservative result.
- Keep comments only if something reads them: a build step, a template marker, or a licence.
- Minify the built output, not the template you edit.
Example
<div class="card">
<!-- the title -->
<h2>Title</h2>
<p>Some <em>text</em> here.</p>
</div>
becomes
<div class="card"><h2>Title</h2><p>Some <em>text</em> here.</p></div>
The space before <em> survives, because deleting it would join two words on screen. The newlines between the block elements do not, because they render as nothing.
Pitfalls
- Whitespace between inline elements is visible text.
<span>a</span> <span>b</span>reads as “a b”; remove the space and it reads “ab”. A minifier that strips all whitespace breaks this every time. preandtextareashow whitespace exactly as written. Both are copied through here without a single character changed.display: inline-blockmakes whitespace matter in layout too, which is why the four pixel gap between inline-block boxes disappears after minification. That is a change, even if it is usually the one you wanted.- Conditional comments are markup, not notes. Removing
<!--[if IE]>changes what old browsers see, so those are kept. - Some templating systems use comments as markers. Minifying a template rather than its output can quietly remove them.
- Attribute quotes are left alone. Dropping them is legal in HTML5 and breaks the moment a value contains a space.
- HTML compresses extremely well. After gzip, the difference between formatted and minified markup is usually a few percent.
- Minified HTML is much harder to debug in view-source. Keep the readable version as the one you edit.
Compatibility
The output is ordinary HTML5 and renders identically in every browser. No tags are removed, no attributes are rewritten, and no optional closing tags are dropped: those are all legal but change what a parser sees in edge cases. The tool runs entirely in your browser and handles documents up to 100,000 characters.
Frequently asked questions
Will this change how my page looks?
Why is there still a space between my tags?
Does it touch my JavaScript or CSS?
script and style contents are copied through untouched. Use a CSS or JS minifier for those.