HTML Minifier

Minify HTML code online. Paste your markup, choose options such as removing comments and collapsing whitespace, and get compressed HTML along with a before-and-after size comparison.

FreeOnline Tool
Loading…

How to Use

  1. Paste the HTML you want to compress into the input box on the left.
  2. Tick the minification options you want, such as "remove comments" or "collapse whitespace".
  3. Click "Minify" and the compressed code appears on the right.
  4. Review the compression ratio, then click "Copy" to put the result on your clipboard.

Features

  • Strips redundant spaces, line breaks and indentation from HTML to cut file size significantly.
  • Optionally removes HTML comments, with a choice of keeping or deleting conditional comments.
  • Merges duplicate attribute values and cleans up redundant tag attributes.
  • Shows the before and after size along with the compression ratio.
  • Handles large files, so it is suitable for production use.

Use Cases

Optimizing a production deployment
Minify HTML templates before a site goes live to reduce the bytes transferred and speed up first paint.
Compressing HTML email templates
Shrink a finished HTML email template before sending, keeping message size down and reducing the chance of spam filtering.
Optimizing CDN assets
Compress static HTML pages hosted on a CDN to lower bandwidth costs and improve load times worldwide.
Verifying a build pipeline
Check the expected minification result in CI/CD to confirm that your build tool's compression settings are actually taking effect.

FAQ

Can minifying HTML break my page?
Normally no. Minification only removes whitespace and comments; it does not change the structure or logic of the markup. Testing the page after minifying is still a good habit.
Can minified HTML be restored to its original formatting?
Minification is one-way, so keep a backup of the original file. If you need readable code again, run the minified output through an HTML beautifier.
Does removing comments also remove IE conditional comments?
No. The remove-comments option keeps IE conditional comments by default, because they have a functional effect in certain browsers.
Will inline script and style blocks be mangled?
No. Content inside script and style tags only receives basic whitespace handling, which does not break the JavaScript or CSS syntax.