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
Paste or Upload Your HTML
Drop your .html file or paste code into the editor.
Choose Options
Pick conservative defaults or enable inline CSS/JS minification.
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.
| Operation | Applied | Notes |
|---|---|---|
| Remove HTML comments <!-- ... --> | ✅ | License comments with <!--! ... --> can be preserved |
| Collapse whitespace & newlines | ✅ | Preserves semantics in <pre>, <code>, <textarea> |
| Trim redundant attributes/semicolons in inline style | ✅ | No reordering of attributes |
| Remove optional end tags (e.g., </li>, </p>) | ✅ Optional | Enabled only when safe |
| Boolean attributes (e.g., disabled) | ✅ | Converts disabled="disabled" → disabled |
| Remove unnecessary quotes | ✅ | When attribute values are safe tokens |
| Minify inline CSS/JS | ✅ Optional | Conservative; preserve templating delimiters |
Preservation Rules
Elements/regions where whitespace or content must be kept.
| Context | Preserved | Notes |
|---|---|---|
| <pre>, <code>, <textarea> | Yes | No whitespace collapsing |
| Inline <script>/<style> | Configurable | Minify only if enabled |
| Server/template markers | Yes | Keeps {{ }}, <% %>, {% %}, ${{ }} etc. |
| Inline SVG/MathML | Yes | Keeps structural whitespace |
Typical Size Reduction
Varies with formatting and comment density.
| Input Style | Typical Savings |
|---|---|
| Heavily formatted with comments | 40%–60% |
| Moderately formatted | 20%–40% |
| Compact already | 5%–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.htmlPopular 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.htmlInstall 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.htmlWorks 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?
Will it break <pre>, <code>, or templates?
Can it minify inline CSS and JS?
How big can my file be?
Is my HTML uploaded to a server?
Pro Tips
Keep an unminified source for debugging; automate minify only in production builds.
Enable inline CSS/JS minify only when your snippets are valid and templating-free.
Pre-compress with gzip/brotli on the server/CDN after minification for maximum savings.
Preserve license comments with <!--! ... --> if required by third-party code licenses.
Additional Resources
Other Tools
- CSS Beautifier
- HTML Beautifier
- Javascript Beautifier
- PHP Beautifier
- Color Picker
- Sprite Extractor
- Base64 Decoder
- Base64 Encoder
- Csharp Formatter
- Csv Formatter
- Dockerfile Formatter
- Elm Formatter
- ENV Formatter
- Go Formatter
- Graphql Formatter
- Hcl Formatter
- INI Formatter
- JSON Formatter
- Latex Formatter
- Markdown Formatter
- Objectivec Formatter
- Php Formatter
- Proto Formatter
- Python Formatter
- Ruby Formatter
- Rust Formatter
- Scala Formatter
- Shell Script Formatter
- SQL Formatter
- SVG Formatter
- Swift Formatter
- TOML Formatter
- Typescript Formatter
- XML Formatter
- YAML Formatter
- Yarn Formatter
- CSS Minifier
- Javascript Minifier
- JSON Minifier
- XML Minifier
- Http Headers Viewer
- PDF To Text
- Regex Tester
- Serp Rank Checker
- Whois Lookup