Skip to content

Menu

HTML Minifier

Minify HTML by removing comments and collapsing whitespace, keeping Outlook conditional comments.

Runs entirely in your browserFormattersFree, no sign-up
Loading tool

01What is HTML Minifier?

HTML Minifier shrinks markup as you type and shows three numbers: Original Size, Minified Size and Savings, all measured in bytes. There are no settings to tune. It applies a fixed set of changes that are safe for how browsers render HTML, and skips anything risky. Here is what it does. Ordinary comments are removed. Conditional comments, such as <!--[if mso]> ... <![endif]--> and the <!--[if !mso]><!--> form, are kept exactly. Outlook's Word-based renderer reads them in HTML email, so deleting them breaks layouts. The tool tells you how many it kept. Whitespace is the tricky part. A run of spaces or line breaks between words collapses to one space instead of vanishing. <b>Hello</b> <i>world</i> still reads "Hello world". A gap is removed completely only where browsers don't draw it. That means next to block-level tags such as div, p, li, td and tr, and between non-rendered tags like meta, link, title and script. Inside tags, extra spaces between attributes collapse to one. Quotes come off simple values, so class="card" becomes class=card. The HTML standard allows unquoted attribute values as long as they contain no spaces, quotes, =, <, > or backticks. Values that need quotes keep them. A space is kept before a self-closing slash so the slash isn't read as part of the value. The contents of pre, textarea, script and style are copied byte for byte. Whitespace there either shows on screen or belongs to code the tool doesn't parse. A worked example. Take a 68-byte snippet: a div with class="box" and id='main', wrapping a paragraph with extra spaces around <b>world</b>. The output is <div class=box id=main><p>Hello <b>world</b> !</p></div>, which is 56 bytes. The indentation went, and so did the quotes. The single spaces between the words stayed. What it won't do: minify inline CSS or JavaScript, remove optional closing tags, or drop default attributes. Dedicated build tools go further than this. Savings on hand-written HTML are usually modest, and gzip or Brotli on your server matters more for transfer size. One layout trap to know about: div is treated as block-level, so the gap between side-by-side inline-block divs disappears. Your markup is processed by JavaScript inside the page and isn't uploaded anywhere.

Email developers trimming templates under client size limits, and web developers shrinking static HTML snippets for embeds. The tool runs entirely in your browser, so your data never leaves your device.

02How to use HTML Minifier

  1. Paste your HTML into Input HTML
  2. Read the Original Size, Minified Size and Savings figures as the output updates
  3. Check the note if conditional comments were kept, then review the Minified HTML box
  4. Click Copy above the Minified HTML output, or Reset to start again

03Worked examples

Input: <div class="box" id='main'> <p>Hello <b>world</b> !</p> </div>
Result: <div class=box id=main><p>Hello <b>world</b> !</p></div>
Whitespace between block tags is removed, but the runs inside the paragraph collapse to one space because they separate inline words; simple attribute values lose their quotes. Size drops from 68 to 56 bytes.
Input: <!-- note --><p>Hi</p><!--[if mso]><table><![endif]-->
Result: <p>Hi</p><!--[if mso]><table><![endif]-->
Ordinary comments are removed, but Outlook/IE conditional comments are kept (counted as 1 here).
Input: <pre> keep this </pre> <span>a</span> <span>b</span>
Result: <pre> keep this </pre><span>a</span> <span>b</span>
Content of pre is copied verbatim, and the space between the two inline spans is kept because it is rendered.
Input: <a href="x"/>
Result: <a href=x />
A space stays before the self-closing slash; without it the slash would become part of the unquoted value.
Input: <meta charset="utf-8"> <title>T</title>
Result: <meta charset=utf-8><title>T</title>
Whitespace between two non-rendered head tags is dropped.
Input: <input type="text" value="a b" disabled>
Result: <input type=text value="a b" disabled>
Quotes stay on value="a b" because the value contains a space. Dropping them would split it into two attributes.

04Common use cases

  • Shrinking an HTML email template while keeping its Outlook conditional comments intact
  • Cutting the size of a long newsletter so Gmail is less likely to clip it
  • Minifying a static snippet before pasting it into a CMS or ad-network embed field with a character limit
  • Reducing HTML fragments that live inside JavaScript strings or JSON config
  • Checking how many bytes indentation and comments add to a hand-written landing page
  • Producing a one-line version of markup for a test fixture or snapshot

05Tips

  • If you lay out elements such as divs side by side with display: inline-block, the whitespace between them is a visible gap; the minifier treats div as block-level and removes that gap, so check those layouts.
  • Gmail clips messages larger than about 102 KB, so minifying a long email template can keep it under the limit.
  • Run inline CSS through a CSS minifier separately if you need it smaller; this tool leaves style and script contents untouched.
  • Look for side-by-side layouts in your CSS before shipping. Spaces between inline elements like spans and links are kept, but spaces next to divs are not.

06Related concepts

HTML optimization, Page weight, TTFB, Gzip compression.

Frequently Asked Questions

What is HTML Minifier?

HTML Minifier is a free, browser-based developer tool on AIDToolStack. Minify HTML by removing comments and collapsing whitespace, keeping Outlook conditional comments. It requires no installation or sign-up and works entirely in your browser.

Is HTML Minifier free to use?

Yes. No sign-up, no fees and no usage cap.

Does HTML Minifier store my data?

No. It runs in your browser; nothing is uploaded.

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe