HTML Minifier
Minify HTML by removing whitespace and comments.
What is HTML Minifier?
An HTML minifier is a tool that removes whitespace, comments, optional tags, and redundant attribute quoting from HTML markup to produce a smaller document that browsers download and parse faster. The output renders identically to the source because none of the trimmed bytes affect the DOM tree the browser builds.
Frontend developers, performance engineers, and CMS template authors use an HTML minifier on every production deploy. A 14 KB hand-authored page typically drops below 9 KB after minification, and shrinks further to roughly 3 KB once Brotli compression runs.
Why use the HTML Minifier
- Shrink documents by 20% to 40%. Removing whitespace and HTML comments alone trims a quarter of most server-rendered pages.
- Faster initial render. Less markup means less time spent on byte streaming, HTML tokenization, and DOM construction before the browser can paint.
- Lower CDN bandwidth. Marketing pages with millions of monthly views save real money per kilobyte trimmed.
- Cleaner email and AMP payloads. Both formats penalize bloat, and email clients silently truncate documents over 102 KB in Gmail.
How to use the HTML Minifier
- Paste your HTML document or fragment into the input panel on the left.
- Click the Minify button at the top of the panel.
- Read the minified output in the right panel. Parser errors appear in red above the panels.
- Copy the result with the Copy button and paste it into your build output, template engine, or email body.
What gets removed
The HTML minifier applies safe transformations only. The DOM tree the browser constructs is identical to what the source produces.
| Pass | Action | Typical savings |
|---|---|---|
| Whitespace collapse | Reduces runs of spaces, tabs, and newlines between tags | 20-30% |
| Comment stripping | Removes <!-- ... --> including conditional comments | 5-10% |
| Attribute quote removal | Drops quotes from safe values (class=btn vs class="btn") | 1-3% |
| Optional tag removal | Drops </li>, </p>, </tr> where the spec allows | 1-3% |
| Boolean attribute shortening | Rewrites disabled="disabled" to disabled | 0.5-2% |
| Empty attribute removal | Drops style="" and class="" | 0.5-1% |
Whitespace inside <pre>, <textarea>, <script>, and <style> blocks is preserved, since those contexts are whitespace-sensitive or have their own parsing rules.
Size savings example
Input (286 bytes):
<!-- Main navigation -->
<nav class="primary-nav">
<ul>
<li><a href="/home">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>Minified output (151 bytes):
<nav class=primary-nav><ul><li><a href=/home>Home</a><li><a href=/about>About</a><li><a href=/contact>Contact</a></ul></nav>Typical savings across page sizes:
| Input | Raw size | Minified | Gzipped | Total reduction |
|---|---|---|---|---|
| Email template | 8 KB | 5.4 KB | 1.9 KB | 76% |
| Marketing landing page | 42 KB | 28 KB | 6.2 KB | 85% |
| Server-rendered listing page | 180 KB | 118 KB | 22 KB | 88% |
| Product detail page with SSR data | 320 KB | 210 KB | 38 KB | 88% |
Common use cases
- Server-rendered HTML responses. Next.js, Rails, Django, and Laravel templates all benefit from a minification pass before the response leaves the origin.
- Email HTML templates. Strips comment annotations from MJML, Maizzle, or Foundation output that bloat the final send.
- AMP pages. AMP requires inline CSS under 75 KB. Minification frees up room for actual styles.
- Static site generators. Hugo, Eleventy, Astro, and Jekyll can pipe build output through the minifier for a smaller
_site/directory.
Frequently asked questions
Is minified HTML reversible?
The whitespace, comments, and dropped optional tags cannot be restored, since the information is not stored anywhere. An HTML prettifier can re-indent the markup for readability, but author comments are gone. Keep your source templates under version control.
Does minifying break my page?
No, as long as the minifier respects whitespace-sensitive contexts. The tool preserves text inside <pre> and <textarea> and leaves <script> and <style> blocks untouched. The rendered output is visually identical to the source.
What is the difference between minify and gzip?
Minification rewrites the HTML itself by removing characters and optional syntax, and the result is still valid HTML the browser can parse directly. Gzip and Brotli are binary compression layers the server applies before sending bytes over the wire. The two stack, and running both delivers roughly 88% total reduction.
Should I minify HTML in development?
No. Minified HTML is hard to read in the browser source viewer, breaks diff tools, and slows down debugging. Apply the HTML minifier only as part of your production build or response middleware.
Will the minifier strip my conditional comments for old IE?
By default, yes. Conditional comments (<!--[if IE]>...) look like normal HTML comments to the parser. If you still target legacy IE, configure the minifier to preserve them, or drop the IE workaround entirely.
Does minified HTML render faster?
Slightly. Browser parsers are fast, but smaller documents reach the parser sooner over slow connections and let the renderer start sooner. The transfer-time savings matter more than parse-time savings.
Can I minify HTML with inline <script> and <style>?
Yes. The HTML minifier leaves the contents of those blocks alone. If you also want to minify the inline JavaScript or CSS, run the relevant sub-tool on those blocks first, then minify the wrapping HTML.
Will minification remove my data attributes?
No. All data-* attributes are preserved, since they may be read by JavaScript at runtime. The minifier only drops attributes with empty values like class="" that have no effect on layout or behavior.
Related tools
- JavaScript Minifier - shrink JavaScript bundles by stripping whitespace and shortening identifiers.
- CSS Minifier - strip whitespace and comments from CSS to shrink stylesheet bundles.
- SQL Minifier - flatten multi-line SQL into a single line for embedded queries.
- HTML Prettify - re-indent minified HTML for inspection and review.
Related tools
ShotMark captures what you do here, in one click.
The traces, payloads, and tests you run by hand? ShotMark grabs the whole bug and hands it to your AI agent.