How to minify HTML online, free and private
HTML minification removes the characters a browser does not need, so the file is smaller to download. Here, paste your markup into HTML Input, or click Open a File, and Minified Output updates as you type. The panels show Original Size, Minified Size, Saved and Reduction. Then click Copy Minified or Download .html.
It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools).
The minifier removes whitespace where browsers ignore it, ordinary comments, and the formatting inside style and script blocks. Every tag and attribute stays. It is not a full JavaScript compressor: it does not rename variables or build source maps, so for external files use the CSS minifier and the JavaScript minifier. To read a minified page again, run it through the HTML beautifier.
Table of Use: what each option does
| Job | Option (default) | Example change |
|---|---|---|
| Remove indentation and line breaks | Collapse whitespace (on) | <h1>Hello</h1> and the next <p> on separate lines join into one line. A space between <b> and <i> is kept. |
| Strip developer comments | Remove comments (on) | <!-- Styles --> is deleted; <!--[if mso]> is kept |
| Shrink style blocks | Minify inline CSS (on) | body { margin: 0; } becomes body{margin:0} |
| Shrink script blocks | Minify inline JavaScript (on) | Comments and indentation go, line breaks stay, and JSON-LD is compacted |
| Shorten boolean attributes | Collapse boolean attributes (on) | disabled="disabled" becomes disabled |
| Drop quotes around simple values | Remove attribute quotes (off) | class="nav" becomes class=nav; a value with a space keeps its quotes |
| Several pages in one go | Minify Several Files (ZIP) | A before-and-after size for each file, then minified-html.zip |
Tags such as <script src="/js/app.js" defer> and <style media="print"> keep every attribute. Content inside pre and textarea tags is never changed. Check the minified page in the HTML previewer, and shrink JSON-LD or API samples with the JSON minifier.
Features
- Minifies as you type. There is no Minify button. The output follows the input, and the size panels show bytes and percent saved.
- Six options. Collapse whitespace, Remove comments, Minify inline CSS, Minify inline JavaScript, Collapse boolean attributes and Remove attribute quotes, each a checkbox with a hint.
- Attributes are safe. Every attribute is kept, including src, defer, async, media and type on script and style tags. Style attributes are left exactly as written.
- Careful with code. The JavaScript pass keeps line breaks, copies strings, template literals and regular expressions unchanged, and only compiles code to check it still parses; it never runs it. If a script cannot be processed with confidence, the original stays.
- Open a File and batches. Load one .html or .htm file, or several at once and download a ZIP with the original names.
- Copy Minified, Download .html, Clear. The download is named minified.html.
- Private and free. No account, and nothing is uploaded or saved.
Shrink the images on the page too, with the image compressor, and turn on gzip or Brotli on your server for a smaller transfer on top of minification. The HTTP header viewer shows whether a page is served compressed.
How to use the HTML minifier
- Paste your HTML into HTML Input, or click Open a File to load a .html or .htm file. The box starts with a sample page; click Clear to empty it.
- Under Minification Options, tick or untick the six checkboxes. The defaults suit most pages.
- Read the Original Size, Minified Size, Saved and Reduction panels.
- Check Minified Output. The counts above the box show lines and characters.
- Click Copy Minified, or Download .html to save minified.html.
- For many files, click Minify Several Files (ZIP), pick the files, review Batch Results and click Download All (ZIP).
- Test the result before publishing. If your CSS makes li or div elements inline-block, or sets white-space: pre on ordinary elements, untick Collapse whitespace and minify again.
Who can use it
- Web developers shipping static pages who want a smaller file without setting up a build tool.
- Email template builders, whose conditional comments for Outlook are kept. Build the table-based HTML with the email template builder, then minify it here.
- SEO and performance specialists checking how much weight whitespace and comments add to a page.
- Writers and theme authors trimming HTML from the Markdown to HTML converter, or snippets pasted into a CMS.
- Students comparing a page before and after, with the text diff tool.
FAQs
How do I minify HTML online?
Paste your HTML into HTML Input, or click Open a File to load a .html file. Minified Output updates as you type, and the panels above show Original Size, Minified Size, Saved and Reduction. Adjust the Minification Options if needed, then click Copy Minified or Download .html. Nothing is uploaded, because the work happens in your browser.
Will minifying HTML break my page?
It is built not to. Every tag and attribute is kept, including src, defer, async, media and type on script and style tags, and whitespace is removed only where browsers ignore it. One space stays between inline elements so words do not run together. The risk is CSS the tool cannot see, such as rules that make li or div inline-block or set white-space: pre. For those pages, untick Collapse whitespace.
How much smaller will my HTML get?
It depends on the page. Hand-written HTML with deep indentation, blank lines and comments shrinks the most, while HTML that a framework has already minified barely changes. The tool shows the exact original and minified sizes in bytes for your input, so you can measure instead of guessing. Gzip or Brotli on your server then compresses the result further.
Does the minifier remove HTML comments?
Yes, when Remove comments is ticked, which it is by default. Ordinary comments are deleted. Conditional comments such as the Outlook block that starts with an if mso test are kept, because many email templates rely on them, and so are comments that begin with an exclamation mark. Untick Remove comments to keep every comment in the output.
Why does the minified JavaScript still contain line breaks?
JavaScript can insert missing semicolons at line breaks, so joining lines could break code written without semicolons. The minifier removes comments and indentation but keeps the line breaks. Strings, template literals and regular expressions are copied exactly, and it does not rename variables. For aggressive compression of external scripts, use the JavaScript minifier or a build tool.
Does it minify JSON-LD and other script types?
JSON script blocks, including JSON-LD, importmap and speculation rules, are compacted without re-reading numbers, so large numbers keep every digit. Classic and module scripts get comment and indentation removal. Script types that are not JavaScript or JSON, such as text/template, are left untouched. If a script cannot be processed with confidence, the original is kept.
Can I minify several HTML files at once?
Yes. Click Minify Several Files (ZIP) and select your .html or .htm files. A list shows each fileโs size before and after, and it recalculates when you change an option. Click Download All (ZIP) to get minified-html.zip with the original file names. The ZIP is built in your browser too, and nothing is sent anywhere.
Is my HTML uploaded to a server?
No. Files are read and minified in your browser, and the ZIP for several files is built there as well, so nothing is uploaded (you can check the Network tab in DevTools). The tool does not save your input: reload the page and the sample returns. It is free, with no account and nothing to install.