Loading…

About Online HTML Minifier

Make your pages leaner in seconds ⚡. Our HTML Minifier removes comments, collapses whitespace, strips optional quotes where safe, and can optionally minify inline CSS/JS. Perfect for production builds, CI/CD, and Core Web Vitals improvements. 100% client-side — your code never leaves your browser.

Key Features

  • Instant, in-browser HTML compression (no uploads)
  • Removes comments, collapses whitespace & line breaks
  • Safe attribute optimizations (quotes/boolean/optional end tags)
  • Smart preserve rules for <pre>, <code>, <textarea>, inline SVG
  • Optional minify of inline CSS/JS (conservative defaults)
  • One-click copy & download of minified HTML
  • Works on desktop & mobile; great in CI/CD

🛠️ How to Minify HTML for html-minifier

1

Paste or Upload Your HTML

Drop your .html file or paste code into the editor.

2

Choose Options

Pick conservative defaults or enable inline CSS/JS minification.

3

Minify & Export

Copy the result or download a .min.html for deployment.

Technical Specifications

Core Transformations (Safe by Default)

Operations applied with conservative settings to keep HTML5 valid.

OperationAppliedNotes
Remove HTML comments <!-- ... -->License comments with <!--! ... --> can be preserved
Collapse whitespace & newlinesPreserves semantics in <pre>, <code>, <textarea>
Trim redundant attributes/semicolons in inline styleNo reordering of attributes
Remove optional end tags (e.g., </li>, </p>)✅ OptionalEnabled only when safe
Boolean attributes (e.g., disabled)Converts disabled="disabled" → disabled
Remove unnecessary quotesWhen attribute values are safe tokens
Minify inline CSS/JS✅ OptionalConservative; preserve templating delimiters

Preservation Rules

Elements/regions where whitespace or content must be kept.

ContextPreservedNotes
<pre>, <code>, <textarea>YesNo whitespace collapsing
Inline <script>/<style>ConfigurableMinify only if enabled
Server/template markersYesKeeps {{ }}, <% %>, {% %}, ${{ }} etc.
Inline SVG/MathMLYesKeeps structural whitespace

Typical Size Reduction

Varies with formatting and comment density.

Input StyleTypical Savings
Heavily formatted with comments40%–60%
Moderately formatted20%–40%
Compact already5%–15%

CLI Alternatives

Use these in CI/CD or for bulk processing.

Node.js

html-minifier-terser (glob)

npx html-minifier-terser --collapse-whitespace --remove-comments --remove-optional-tags --minify-css true --minify-js true -o dist/index.min.html src/index.html

Popular Node-based HTML minifier with CSS/JS options

Linux/macOS

minify-html (Rust, very fast)

minify-html --keep-whitespace=false --minify-css --minify-js src/index.html > dist/index.min.html

Install via cargo or pkg manager; excellent performance

Windows

PowerShell + html-minifier-terser

npx html-minifier-terser --collapse-whitespace --remove-comments -o .\dist\index.min.html .\src\index.html

Works in PowerShell or CMD

Common Use Cases

Web Performance

  • Reduce HTML transfer size
  • Help LCP/FCP by shipping fewer bytes
  • Trim comments before deploy
<!-- Remove this in production -->

CI/CD Automation

  • Minify during build (Vite/Webpack/Next.js export)
  • Pre-compress with gzip/brotli after minify
  • Bundle static sites for CDNs

A/B Testing & Templating

  • Ship compact templates
  • Preserve placeholders for SSR/ISR
  • Avoid breaking whitespace-sensitive regions

❓ Frequently Asked Questions

What does HTML minification do?

It removes unnecessary characters (comments, extra whitespace, some optional tags/quotes) without changing how the page renders. Result: smaller files and faster loads.

Will it break <pre>, <code>, or templates?

No. Those contexts are preserved by default. Template markers like {{ }}, <% %>, and {% %} are not touched.

Can it minify inline CSS and JS?

Yes, optionally. For safety, it’s off in conservative mode. Turn it on when your inline code is valid and self-contained.

How big can my file be?

For smooth browser UX, we recommend up to ~1 MB. Larger pipelines should use the CLI tools listed above.

Is my HTML uploaded to a server?

No. Processing is 100% client-side in your browser for speed and privacy.

Pro Tips

Best Practice

Keep an unminified source for debugging; automate minify only in production builds.

Best Practice

Enable inline CSS/JS minify only when your snippets are valid and templating-free.

Performance Tip

Pre-compress with gzip/brotli on the server/CDN after minification for maximum savings.

Best Practice

Preserve license comments with <!--! ... --> if required by third-party code licenses.

Additional Resources

Other Tools