HTML Minifier

Reduce HTML size by removing comments and redundant whitespace, without breaking <pre> blocks or inline spacing. Inline CSS and JavaScript can be minified too.

Loading tool…

About the HTML Minifier

Whitespace in HTML is not always removable. Between two inline elements, as in <b>Hello</b> <i>world</i>, a space is rendered on screen. This minifier collapses every run of whitespace to a single space and removes it completely only next to block-level and metadata elements such as <div>, <p>, <li>, <head> and <meta>, where browsers ignore it anyway. The content of <pre>, <textarea>, <script> and <style> is never collapsed.

Comments are removed except Internet Explorer conditional comments (<!--[if lt IE 9]>), which some e-mail templates still depend on. Tags are tidied: extra spaces between attributes are removed, while attribute values stay exactly as written. With Minify inline CSS the <style> blocks go through the CSS Minifier; with Minify inline JS classic and module <script> blocks go through Terser, and JSON-LD blocks are compacted. A script that fails to parse is left untouched and noted in the status line.

Server-side templates (Handlebars, Jinja, PHP) usually pass through intact, but check the result if tags are generated dynamically. The status line shows original, minified and gzip sizes. Processing happens in your browser.

How to use it

  1. Paste HTML or open an .html file.
  2. Choose whether to remove comments and minify inline CSS and JS.
  3. Compare the sizes in the status line.
  4. Copy the output or download index.min.html.

Frequently asked questions

Can HTML minification change how my page looks?
Aggressive minifiers can remove spaces between inline elements and join words together. This tool keeps one space wherever whitespace can be visible, so rendering stays the same.
Are attribute quotes removed?
No. Removing quotes saves little after gzip and can break values containing spaces or special characters, so quotes are kept.
What happens to inline event handlers like onclick?
They are left as they are. Only whitespace between attributes is collapsed; attribute values are never modified.

Related tools