What does an HTML minifier do?
An HTML minifier removes everything a browser does not need to render a page: comments, indentation, line breaks and runs of spaces. The result is functionally the same document in fewer bytes, which means less to download and parse — useful for static sites, HTML email, landing pages and inline snippets you paste into widgets or ad slots.
The hard part is doing it safely. Whitespace in HTML is not always insignificant: the space in <b>Hello</b> <i>world</i> is visible, while the spaces between </li> and <li> are not. This minifier tokenizes the markup and only removes whitespace next to block-level elements, collapsing any other run to a single space. Content inside <pre>, <textarea> and <script> is never reflowed, so code samples, form defaults and JavaScript keep working.
Gains vary with how the source was written. Hand-indented templates commonly shrink by 10–25%, but most of the transfer saving on a live site comes from gzip or Brotli compression on the server, which already squeezes repeated whitespace. Minify for tidier deliverables and a few extra kilobytes; enable server compression for the big win.
How to use the HTML Minifier
- Paste your HTML into the input box or click Sample to try a small page.
- Pick the optimisations you want. The defaults are all safe for standard HTML5 pages.
- Check the original size, minified size and percentage saved shown below the editor.
- Copy the result or download it as
minified.html. Keep your readable source file for future edits.
Example
Indented markup with a comment and a redundant boolean value. Note the single space kept between the input and the button — both are inline, so that gap is visible:
<!-- Signup -->
<form>
<input type="email" required="required">
<button>Join <b>now</b></button>
</form>
→ <form><input type="email" required> <button>Join <b>now</b></button></form>Which options are safe?
- Remove comments — safe for normal pages. Keep conditional comments if you build HTML email for Outlook or still support very old Internet Explorer.
- Collapse whitespace — safe with this tool, because a single space is always kept between inline elements and text where it can affect rendering.
- Minify inline CSS — removes comments and extra spaces inside
<style>; selectors and values are never rewritten. - Remove default type attributes —
type="text/javascript"andtype="text/css"are the defaults in HTML5. Other types such asmoduleorapplication/ld+jsonare kept. - Collapse boolean attributes —
checked="checked"andcheckedare identical in HTML. Leave it off if the output must be valid XHTML.
Frequently Asked Questions
Can minifying HTML break my page?
A careless minifier can, mainly by removing spaces between inline elements or reflowing preformatted text. This tool keeps significant spaces, leaves <pre>, <textarea> and scripts untouched, and never rewrites attribute values. Still, test the output in a browser before deploying, especially if your CSS uses white-space: pre on ordinary elements.
Does it minify JavaScript too?
No. Inline scripts are only trimmed. Safe JavaScript minification needs a full parser (it must understand strings, regular expressions and automatic semicolon insertion), so use your build tool — esbuild, Terser or similar — for scripts.
Is it worth minifying HTML if my server uses gzip or Brotli?
Compression already removes most of the cost of whitespace, so the transfer saving after compression is usually small. Minifying still reduces the uncompressed size the browser parses and the size of cached pages, and it strips comments you may not want to publish.
Should I minify HTML in WordPress manually?
Not for theme files you still edit. Caching plugins such as WP Rocket, LiteSpeed Cache or Autoptimize can minify the generated HTML on the fly. Use this tool for static pages, email templates and snippets you paste into widgets or custom HTML blocks.
How do I turn minified HTML back into readable code?
Paste it into the HTML Formatter, which re-indents it while preserving the same whitespace rules. Comments that were removed cannot be recovered, so keep your original source.