HTML Minifier

Minify HTML, including inline CSS and JavaScript

Shrink HTML by removing comments and collapsing whitespace, and optionally minify inline <style> and <script> blocks. Content inside <pre> and <textarea> is preserved.
Try an example:

Output will appear here...

About HTML Minifier

How it works

  1. <pre>, <textarea>, <script> and <style> blocks are set aside so their content is not altered by whitespace collapsing.
  2. Comments are removed (except old Internet Explorer conditional comments) and runs of whitespace become a single space; space between tags is removed.
  3. If enabled, inline CSS is minified and inline JavaScript is compressed with Terser.

What you need

  • HTML - a full page or a fragment.

Tips

  • Minifying typically saves 10-25% on HTML; enabling gzip/brotli compression on your server saves far more - do both.

Limitations

  • Whitespace between inline elements (e.g. two <a> tags) is collapsed to one space but never fully removed, so text does not run together.

Runs in your browser. Everything happens in your browser - your code and data are never uploaded.

Frequently asked questions

Is minified HTML safe?+

Yes - browsers ignore the removed whitespace and comments. Keep your original source for editing, and minify as a build step.