Embed this tool on your site
About this tool
HTML Minifier shrinks HTML by removing comments and collapsing whitespace. Paste a document or fragment and the minified output updates as you type, with input and output byte counts. Three options control it: Remove comments (conditional IE comments are kept), Collapse whitespace, and Preserve case — untick it to lowercase tag and attribute names. Text inside <script>, <style>, <pre> and <textarea> is skipped while collapsing, but a final cleanup still removes whitespace that sits directly before any < character, including inside those blocks. That cleanup also removes the space between a word and a following tag, so Hello <b>world</b> becomes Hello<b>world</b> and renders as Helloworld; review text-heavy output before you deploy it, or untick Collapse whitespace. The tool does not remove optional closing tags, unquote attributes, or minify inline CSS and JavaScript. Everything runs in your browser.
Why use it
Faster Time-to-First-Byte: Every byte removed from an HTML response is processed sooner by the browser. Minified HTML reduces TTFB for uncached responses and decreases the payload the CDN edge must forward to the client.
Comment Stripping: HTML comments like <!-- TODO: fix this --> are invisible to users but add bytes to every response. Remove comments strips them, while conditional IE comments are kept.
Exact Byte Counts: Input and output byte counters show exactly how much the minified version saves.
Lowercase Option: Untick Preserve case to lowercase tag and attribute names, which tidies markup exported in upper case.
Compounds Well with Gzip: Minification and compression are complementary, not competing. Removing repetitive structural characters before gzip gives the compression algorithm more consistent patterns to work with, improving the compression ratio.
No Build Pipeline Required: Static sites, HTML email templates, and single-file utilities can be minified here without wiring up a gulp, webpack, or Vite build step. Paste, minify, deploy.
How to use
- Paste your HTML document or template fragment into the Input HTML box.
- The minified output updates as you type, with Input bytes and Output bytes counters below.
- Use the Remove comments, Collapse whitespace and Preserve case checkboxes to control the transformations.
- Check inline text in the output: with Collapse whitespace on, spaces before tags are removed, so words next to <b>, <a> or <span> can run together.
- Click Copy to copy the minified HTML to your clipboard.
- Click Clear to empty both boxes and reset the counters.
When it helps
- Before uploading a static HTML file to a CDN origin or S3 bucket for a production deployment.
- When optimising HTML email templates where payload size affects deliverability and render speed in email clients.
- After generating HTML from a templating engine to strip the human-readable whitespace added for template author convenience.
- When running a Lighthouse audit that flags render-blocking HTML size as a performance opportunity.
- Before publishing a single-file utility or code pen that needs to fit within an embed or paste size limit.
- When comparing two versions of a template by first minifying both — to eliminate formatting-only diffs — before diffing for real changes.
Examples
01Page header with comments and whitespace
Input<!-- Site header -->
<header class="site-header">
<nav class="main-nav">
<ul>
<li><a href="/tools">Tools</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
</header>
Expected result<header class="site-header"><nav class="main-nav"><ul><li><a href="/tools">Tools</a></li><li><a href="/about">About</a></li></ul></nav></header>
02Lowercase upper-case markup (Preserve case off)
Input<DIV CLASS="box">
<!-- note -->
<P>Text</P>
</DIV>
Expected result<div class="box"><p>Text</p></div>
Input<table class="data-table">
<tr>
<td>Alice</td>
<td>98</td>
</tr>
</table>
Expected result<table class="data-table"><tr><td>Alice</td><td>98</td></tr></table>
Tips
- Always test minified HTML in a browser before deploying — edge cases around inline whitespace can cause text to run together in rare layouts.
- Keep the formatted source HTML in version control and only deploy the minified output; debugging minified HTML in production DevTools is painful.
- Conditional comments (<!--[if lt IE 9]>) are kept even with Remove comments on, so legacy IE blocks survive minification.
- For HTML emails, consider leaving Collapse whitespace off — email text with inline links and bold words is especially prone to words running together.
- Combine with server-level gzip or Brotli — a 20% minification saving followed by 70% compression saving gives an overall 76% reduction in wire weight.
Frequently Asked Questions
Will minifying HTML break my page layout or JavaScript?⌄
It can. With Collapse whitespace on, the tool removes whitespace before every tag, so text such as Hello <b>world</b> becomes Hello<b>world</b> and the words run together. Untick Collapse whitespace for text-heavy pages, or check the output carefully.
Does the minifier remove whitespace inside <pre> or <code> blocks?⌄
Partly. Text inside <pre>, <textarea>, <script> and <style> is skipped while collapsing, but a final cleanup still removes whitespace directly before any < inside them, such as a line break before a tag in <pre>. <code> is not treated specially.
Does it remove optional closing tags?⌄
No. Closing tags such as </li>, </td> and </p> are kept. HTML5 allows omitting some of them, but this tool does not do it.
Can I minify HTML that contains Jinja, Handlebars, or Twig template syntax?⌄
Only if you minify the rendered output, not the source template. Template delimiters like {{ and {% can be broken by whitespace removal if the minifier doesn't understand template syntax.
Does the tool handle HTML with embedded <style> and <script> blocks?⌄
No. Their content passes through unchanged apart from whitespace before < characters. Use the CSS Minifier and JavaScript Minifier tools on those blocks separately.
Should I minify my HTML at build time or at the server level?⌄
Both approaches work. Build-time minification is preferred for static sites since it produces fixed artefacts. Server-side minification via middleware is appropriate for dynamic pages but adds response latency.
What is the typical size reduction for a real HTML page?⌄
Content-heavy pages typically save 8–20%. Framework-generated or template-heavy pages with large comment blocks can save 25–35%. The Input bytes and Output bytes counters show the exact reduction for your input.
Does it remove attribute quotes?⌄
No. Attribute quotes are left as written. Unticking Preserve case lowercases attribute names but does not change their values.
Glossary
- Optional Closing Tags
- HTML5 closing tags that browsers do not require to correctly parse the document, including </li>, </p>, </td>, and </tr>. Omitting them is spec-compliant and saves bytes.
- Whitespace Collapsing
- Reducing sequences of spaces, tabs, and newlines between HTML elements to nothing or a single space. Safe between block elements; must be done carefully between inline elements.
- Render-Blocking
- HTML, CSS, or JS resources that the browser must fully download and process before it can paint the first pixel of the page. Smaller HTML reduces the time spent in this blocking phase.
- Time to First Byte (TTFB)
- The time between a browser sending an HTTP request and receiving the first byte of the response. Smaller HTML files reduce TTFB on uncached requests.
- Inline Script
- JavaScript placed directly in an HTML file inside <script> tags rather than loaded from an external file. Minifying inline scripts as part of HTML minification reduces their byte count without a separate build step.
- Attribute Quoting
- In HTML5, attribute values containing only alphanumeric characters, hyphens, underscores, periods, and colons may be written without quotes. Removing quotes from eligible attributes saves a small number of bytes per attribute.
A LITTLE HELP. A LOT DONE.
Good tools.
Great flow.
Your shortcut to the everyday. Create, convert, calculate,
and get back to what you love.
✳
✳
✓ Free to use✓ No sign-up✓ 500+ possibilities