How to Minify HTML
HTML is the first thing a browser downloads, so trimming it shortens the wait before anything else can start. The catch is that HTML minification is easy to get wrong: whitespace is meaningful in some places and irrelevant in others, and a tool that treats the whole document uniformly will happily destroy a code sample or corrupt inline JavaScript. This minifier handles that properly. Before touching anything, it extracts every pre, textarea, script and style block and sets them aside, restoring them byte-for-byte at the end — so formatted code samples keep their indentation and your inline scripts stay valid. Ordinary comments are stripped, but legacy conditional comments are kept by default because removing them genuinely changes how older browsers render the page. Each optimisation is an individual toggle rather than a single aggressive preset, so if trimming between tags causes a spacing issue in your layout you can turn just that off and keep the rest. A live readout shows the original size, minified size and percentage saved with a progress bar, updating as you adjust options. Everything runs in your browser.
Paste your HTML
Drop in a page or fragment; it's processed locally.
Choose optimisations
Toggle comments, whitespace, tag trimming and empty attributes.
Copy or download
Take the minified markup or save it as an .html file.
Why Minify HTML?
First byte to first paint
The HTML document is downloaded before the browser even knows which CSS and scripts it needs. Trimming it shortens that first round trip, which shows up directly in Core Web Vitals.
Where the savings come from
Indentation and the whitespace between tags usually dominate a hand-written page. Comments add more. None of it affects rendering, so it's pure overhead on every single request.
Common Use Cases
Static site pages
Minify pages before uploading when there's no build pipeline.
Email templates
Shrink HTML emails, where size limits and clipping are real.
Landing pages
Cut bytes on a page where every millisecond of load time matters.
CMS templates
Compress theme markup before deploying it.
Embedded widgets
Minify a snippet others will paste into their pages.
Ad or iframe markup
Reduce a fragment that gets requested many times over.
Check a saving
See how much a page can shrink before wiring up a build step.
Strip comments
Remove internal notes before markup goes public.
Tips & Best Practices
Always check the rendered page
Inline elements can be whitespace-sensitive, so load the minified page and look at spacing before shipping.
Keep the readable source
Minify at deploy time and commit the formatted version, so diffs stay reviewable.
Turn off tag trimming if spacing breaks
Removing whitespace between inline tags can close a gap your layout relied on — that toggle exists for a reason.
Minify CSS and JS separately
This tool leaves script and style blocks alone by design; use dedicated minifiers for those.
Enable compression too
Brotli or gzip on top of minification gives the smallest transfer size.
Remove comments before publishing
Internal notes in markup are visible to anyone viewing source.
Troubleshooting
Spacing between elements disappeared
Trimming between tags removed a whitespace gap your inline layout depended on. Turn that option off.
My code sample lost its formatting
It shouldn't — pre and textarea blocks are preserved. Check the code isn't in a plain div instead.
My inline script broke
Script blocks are left untouched by this tool. If something changed, the issue is likely elsewhere in the markup.
The conditional comment vanished
Enable the keep-conditional-comments option, which is on by default when comment removal is active.
Frequently Asked Questions
How do I minify HTML for free?
Paste your markup above and the minified version appears instantly with a saving readout. Copy or download it — free, no signup.
Will it break my page?
Whitespace-sensitive blocks are preserved and every optimisation is optional, but always check the rendered page after minifying.
Does it preserve pre and textarea?
Yes. Those blocks are extracted before minification and restored byte-for-byte.
Are script and style blocks touched?
No. Inline JavaScript and CSS are left exactly as written, so nothing can be corrupted.
What are conditional comments?
Legacy comments that target old Internet Explorer versions. Removing them changes rendering, so they're kept by default.
What does trim between tags do?
It removes whitespace between adjacent tags, usually the largest single saving — but it can close intentional gaps between inline elements.
Why remove empty attributes?
An attribute like class="" has no effect but still costs bytes on every request.
How much smaller will my HTML get?
Typically 20 to 40 percent for hand-written markup. The live readout shows your exact saving.
Should I use gzip as well?
Yes. Minification and compression are complementary — minify first, then let the server compress.
Is my markup sent to a server?
No. Everything runs in your browser, so your HTML never leaves your device.
Can I minify just a fragment?
Yes. A partial snippet works exactly like a full document.
Does it remove closing tags?
No. Some minifiers drop optional closing tags, but that trades robustness for a few bytes, so this tool keeps them.
Does it minify inline CSS?
No. Style blocks are preserved intact — use our CSS minifier for those separately.
Can I download the result?
Yes. Save it as an .html file, or copy it to your clipboard.
Does it validate my HTML?
No. It compresses rather than validates, so malformed markup stays malformed.
Does it work offline?
Once the page has loaded it runs entirely in your browser, so it keeps working without a connection.
Does it work on phones?
Yes, in any modern browser on Windows, Mac, Android or iPhone with nothing to install.
Is this tool really free?
Completely free, forever — no account, no ads and no premium wall.
100% free · No signup · Processed in your browser · Data never sent
Last updated: August 2026 · FlipMyFormat HTML Minifier
Written and maintained by the FlipMyFormat team · Runs entirely in your browser