How to minify HTML
- Paste your HTML into the box above.
- Leave Keep HTML comments off unless your build needs them.
- Read the minified output that appears right away.
- Check the saving in characters.
- Copy the result or download it.
What this HTML minifier gives you
- Space between tags removed wherever it is safe.
- One space kept between text runs so words never join.
- Exact copies of pre and textarea content.
- Collapsed space inside script and style with no code changes.
- Comments removed by default with an option to keep them.
- Tidy space inside tags with attribute values left alone.
Where the bytes hide in an HTML page
A formatted page carries a lot of indent. Think of a component inside a card inside a grid inside a section. That markup can sit ten or twelve levels deep. Each line then starts with about two dozen spaces. Across a few hundred lines that adds up.
Comments add more. Build notes and old blocks of commented code ship to every visitor. Generator banners do too. Every browser ignores all of them.
The mistake a careless HTML minifier makes
Some tools remove all space between tags. That breaks pages. Space between inline elements matters.
Take two links with a space between them for Terms and Privacy. Remove the space and the page shows "TermsPrivacy". This tool keeps a single space wherever text runs meet. It removes space only where no text sits on either side. It saves a little less than some tools. It never quietly changes how a page reads.
What the tool protects
| Part | What happens |
|---|---|
| pre and textarea | Kept byte for byte because the page shows the spaces |
| script and style | Space collapsed but code never rewritten |
| Attribute values | Never touched so class lists keep their spacing |
| Conditional comments | Kept when you turn on the comments option |
How much does HTML minification matter?
Be realistic. Almost every server sends pages with gzip or brotli. Those squeeze indents very well because indents repeat so much. So the real saving in transfer is modest. Expect a few percent of the bytes that travel.
It still belongs in a build. It will not fix a slow page though. Images cost the most on almost every site. The image compressor will do more for load time than any markup trick.
Never edit the minified version
Treat minification as a build step like you do for CSS and JavaScript. The formatted file is your source. The minified file is output.
Lost the source? The HTML formatter can rebuild a readable version. Comments removed during minification are gone for good though.
Why the tool leaves attribute values alone
A class list with double spaces looks messy. A quick tidy seems harmless. Some scripts read attribute values exactly as written. A data attribute may hold text that needs its spacing. So the tool trims space between attributes and never inside a value.
A safe HTML minifier workflow
- Keep the readable file as your source.
- Edit and review only that source file.
- Minify a copy before you upload it.
- Open the minified page and check the spacing.
- Compress images on the same page for a bigger win.
This order keeps your work safe. A team never loses edits to a build that overwrote them.
Common HTML minifier problems
A gap disappeared between two items
The items had no text between them. Add a real space or use CSS margins for the gap.
An old browser feature stopped working
Your page may rely on conditional comments. Turn on the option to keep comments and run it again.
The saving looks small
Your markup was already compact. Most of its size may sit in text or inline data.
Tips for a faster page
- Compress and resize images before anything else.
- Turn on gzip or brotli on your server.
- Minify CSS and JavaScript along with HTML.
- Remove scripts that no page needs.
- Cache static files in the browser for repeat visits.
Who uses an HTML minifier?
Web developers shrink templates for production. Email designers trim newsletters that hit size limits. Bloggers clean exported pages. Agencies prepare landing pages for launch.
Your pages stay private
The tool runs in your browser. Unreleased pages and internal templates never leave your device. Need to shrink styles and scripts too? Try the CSS minifier and the JavaScript minifier.