HTML Minifier
Strip comments and collapse whitespace from HTML. See how many bytes you save.
About the HTML Minifier
HTML minification reduces page transfer size by removing characters browsers do not need: whitespace between tags, HTML comments, optional closing tags, and redundant attribute syntax. A typical HTML page reduces by 10-25% through minification alone, improving load time and reducing bandwidth costs — particularly valuable for high-traffic pages.
What HTML minification removes
- Whitespace — spaces and newlines between tags collapsed to a single space or nothing
- Comments — <!-- ... --> blocks stripped (conditional comments for IE can be preserved)
- Optional end tags — </p>, </li>, </option> are valid to omit in HTML5
- Redundant type attributes — type="text/javascript" on <script>, type="text/css" on <style> are defaults and can be removed
Minification vs compression
Minification reduces source code size on disk. HTTP compression (gzip/Brotli) further reduces the bytes transferred over the network. Apply both: minify HTML files during your build step, then configure your web server to serve them with compression. Together they typically reduce HTML page size by 70-80%.
HTML minification in a build pipeline
Modern web build tools integrate HTML minification automatically. Webpack's HtmlWebpackPlugin minifies output by default in production mode. Vite minifies HTML files. Next.js and Nuxt.js minify server-rendered pages. For static sites without a bundler, html-minifier-terser run as a post-build step achieves the same result.
- Webpack + HtmlWebpackPlugin — set minify options in the plugin config
- Vite — HTML is automatically minified in production builds with no configuration needed
- Next.js — minifies all HTML output in production; controlled via next.config.js
- Static sites — run
npx html-minifier-terser --collapse-whitespace -r src/ -o dist/as a build step
Frequently Asked Questions
npx html-minifier-terser --collapse-whitespace --remove-comments input.html -o output.html. In webpack use HtmlWebpackPlugin with minification options. Vite and Next.js minify HTML automatically in production builds.