HTML Minifier

Compress HTML by collapsing whitespace, dropping comments and redundant attributes, and minifying the CSS and JS inside it.

HTML
Minified HTML
Runs locally in your browser

About the HTML Minifier

This minifier runs html-minifier-terser, the same library used by many build tools, entirely in your browser. It collapses runs of whitespace between elements, removes comments (except conditional comments), drops attributes that equal their defaults such as type="text" on an input, shortens boolean attributes and the doctype, and runs the embedded CSS through a CSS minifier and the embedded JavaScript through terser.

Whitespace inside <pre> and <textarea> is preserved because it is significant there. Attribute quotes are kept by default; removing them saves a few bytes but is easy to get wrong in templating systems, so it is an option. Typical savings are 10 to 25 percent before gzip on hand-written pages and more on generated ones.

Use it for email templates, embedded widgets, static pages served without a build step, or to measure how much of a page is whitespace. Gzip or brotli on the server still matters more than minification, so treat this as the finishing step, not the main one.

How to use

  1. Paste the HTML or upload the file.
  2. Decide whether inline CSS and JS should be minified and whether comments must be kept.
  3. Copy the single-line output or download it.

Common questions

Is it safe to remove attribute quotes?
It is valid HTML5 when the value has no spaces or special characters, and the minifier only removes quotes in those cases. Leave the option off if the HTML is a template with variables inside attributes.
Are conditional comments for old IE removed?
No. Conditional comments are kept; only ordinary comments are removed.
Why did an inline script fail to minify?
If the JavaScript has a syntax error, terser cannot process it and the tool reports the error. Fix the script or untick "Minify inline JS".
Does minifying change how the page renders?
Collapsing whitespace between inline elements can remove a visual space in rare layouts that depend on it. Check the result in the HTML Viewer.