HTML Minifier
Minify HTML online. Strip comments, whitespace, and reduce file size for faster page loads.
Paste HTML and click Minify to strip comments and collapse whitespace. Reduces page weight and improves Core Web Vitals.
Use it to create a smaller deploy copy while keeping your readable source HTML unchanged.
Input HTML
Minified Output
Why Minify HTML?
HTML minification removes whitespace and comments that browsers don't need. A typical HTML page can shrink by 15-30% after minification. That's bytes that don't travel over the network, don't get parsed, and don't slow down your page load.
Is it the biggest performance win? No, that's images, JavaScript, and CSS. But HTML minification is free performance. It costs nothing to implement and compounds with every page view. For a site with millions of visits, a 20% reduction in HTML size saves real bandwidth and money.
Paste your HTML, get a minified version. The tool strips comments and collapses whitespace while preserving your tags, attributes, and links. For most pages the output renders identically, just smaller.
What Minification Removes
| Element | Before | After | Savings |
|---|---|---|---|
| Whitespace | <p> Hello </p> | <p>Hello</p> | Usually 15-25% of file size |
| Comments | <!-- Navigation --> | (removed) | Varies, can be significant |
| Newlines | Multiple line breaks | Collapsed to single space | 5-10% typical |
What this means for you: Minification is safe and reversible. If you need to debug, use the HTML Beautifier to re-format. Most build tools (Vite, webpack) can minify HTML automatically during production builds.
Performance Optimisation Beyond Minification
Enable Gzip/Brotli compression
Server-side compression reduces HTML by 60-80%. Minification + Brotli together can reduce a 100KB page to under 10KB over the wire. Most CDNs and web servers support this with one config line.
Inline critical CSS
Put above-the-fold CSS directly in <style> tags to avoid render-blocking requests. The page renders instantly while the full stylesheet loads asynchronously. This is the #1 LCP optimisation.
Defer non-critical scripts
Add defer or async to <script> tags that aren't needed for initial render. Analytics, chat widgets, and social media embeds can all load after the page is interactive.
Remove unused code
Unused CSS and JavaScript are a bigger problem than unminified HTML. A single unused 50KB JS bundle dwarfs any HTML whitespace savings. Audit with Chrome DevTools Coverage tab.
Typical HTML Page Sizes
| Page Type | Raw HTML | Minified | Minified + Gzip |
|---|---|---|---|
| Simple landing page | 15 KB | 11 KB | 3 KB |
| Blog article | 30 KB | 22 KB | 7 KB |
| E-commerce product page | 80 KB | 55 KB | 15 KB |
| Dashboard (heavy tables) | 200 KB | 140 KB | 30 KB |
| Average web page | 50 KB | 35 KB (30%) | 10 KB (80%) |
HTML is rarely the performance bottleneck, images and JavaScript are far larger. But minification is free savings with zero risk, and it's standard practice in every production build pipeline.
Worked Example: Shipping a Static HTML Page
Priya has a static product page with hand-written HTML. The readable source is 42 KB because it has comments, indentation, and clear sections for header, features, FAQ, and footer.
1. Keep source readable
She keeps index.html readable in version control so future edits are easy to review.
2. Create a deploy copy
She pastes the HTML into the minifier and saves the output as the published file. Comments and indentation are removed from that copy only.
3. Test whitespace-sensitive blocks
The page has a small code example inside pre. She checks that it still displays correctly after minification.
4. Check the network panel
In DevTools, the minified HTML is smaller before compression and smaller again after brotli or gzip is applied by the host.
HTML Minification Edge Cases
pre and code blocks
Whitespace can be meaningful inside code examples, poetry, command output, and ASCII diagrams. Test those areas after minifying a content-heavy page.
textarea defaults
Textarea content is visible to the user and may preserve spacing. Avoid collapsing intentional spaces inside form examples or templates.
Email conditional comments
Old Outlook email templates can rely on conditional comments. If you are minifying HTML email, test the output in the clients you support.
Inline scripts and styles
This page focuses on HTML whitespace. Minify complex inline CSS and JavaScript with tools made for those languages when size matters.
What to Test After Minifying
| Area | Check | Why |
|---|---|---|
| Layout | Header, nav, main content, and footer still render | A pasted partial document can lose context when reused |
| Links | Internal anchors and external links still work | HTML minification should not change href values |
| Forms | Labels, required fields, and submit buttons still behave | Forms often expose subtle markup errors quickly |
| Structured data | JSON-LD script blocks remain valid JSON | Whitespace is safe, but broken script tags are not |
| Analytics and embeds | Third-party snippets still load in the browser console | Some snippets are sensitive to copied or trimmed code |
Safe HTML Minification Workflow
- Keep a readable source file. Comments and indentation help future edits, so treat minified HTML as output.
- Minify after template rendering. If a CMS or build step injects content, minify the final output rather than a half-rendered template.
- Check generated source in a browser. Use View Source or DevTools to confirm the minified file is the one being served.
- Pair it with compression. Minification reduces source bytes. Gzip or brotli reduces transfer bytes.
- Avoid editing the minified copy. If you need a change, edit the readable source and create a fresh minified output.
Related Tools
How to use this tool
Paste your HTML into the input area
Click Minify HTML to compress
Copy the result or download as a .min.html file
Common uses
- Reducing HTML file size for production deployment
- Stripping comments from HTML before going live
- Preparing HTML email templates for sending
- Optimising static HTML pages for faster load times
Share this tool
Frequently Asked Questions
What does HTML minification do?
Will minification break my page?
Is my HTML sent to a server?
Should I minify HTML for production?
What's the difference between minification and compression?
Does minification remove my CSS and JavaScript?
Can I undo minification?
How much space will I save?
Should I minify HTML or just rely on Gzip?
Does Google care about minified HTML?
What about whitespace in pre tags?
Can I minify HTML automatically in my build?
Should I minify HTML email?
Does minification remove analytics scripts?
Can minified HTML still be crawled?
What should I preserve before minifying?
Can I minify a single HTML component?
What happens to conditional comments?
Results are for general informational purposes only and should be checked before use. They are not professional advice. See our Disclaimer and Terms of Service.