HTML Minifier
Remove whitespace and comments from HTML to reduce file size.
HTML minification explained
HTML minification reduces the size of HTML documents by removing characters that are irrelevant to how browsers render the page. Unlike CSS or JavaScript, HTML minification has a more limited impact because HTML documents are often smaller than stylesheets and scripts. However, for high-traffic pages where every kilobyte matters, or for HTML email templates sent to millions of recipients, minification provides meaningful gains.
What gets removed during HTML minification
| Removed element | Safe to remove? | Notes |
|---|---|---|
| HTML comments | β Yes | Not rendered by browser; strip all except conditional comments for IE |
| Whitespace between tags | β Usually | Safe in most cases; can affect inline elements in some edge cases |
| Optional closing tags | β Yes | <li>, <p>, <tr> closing tags are optional per the HTML spec |
| Attribute quotes (sometimes) | β Context-dependent | Only safe if attribute values contain no spaces or special chars |
| type="text/javascript" | β Yes | Default in HTML5; no longer required on <script> tags |
| type="text/css" | β Yes | Default in HTML5; no longer required on <style> and <link> tags |
| Boolean attributes | β Yes | "disabled="disabled"" β just "disabled" |
| Inline style whitespace | β Yes | Extra spaces in style="" attribute values can be removed |
HTML minification in a build pipeline
In modern web development, HTML minification is typically automated as part of a build process rather than done manually. Tools like webpack, Vite, Parcel, and Next.js can apply HTML minification automatically during production builds. For static sites, tools like HTMLMinifier-terser or html-minifier-terser provide command-line minification.
# Using html-minifier-terser (Node.js)
npx html-minifier-terser --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype input.html -o output.min.htmlFrequently asked questions
Does minifying HTML break my page?
No. Minification only removes characters browsers ignore β extra whitespace, comments and optional tags. The rendered page is identical. Just keep your unminified source file for editing.
How much smaller does HTML get?
Typically 10β30% before server compression. Combined with Gzip or Brotli on the server, the total transfer size drops much further.
Should I minify HTML or just rely on Gzip?
Both β they stack. Minification removes redundant characters from the source; Gzip/Brotli then compresses what remains for transfer over the network.
Is minified HTML bad for SEO?
No. Search engines parse minified HTML without any problem. Smaller, faster-loading pages can actually help rankings through better Core Web Vitals scores.