HTML minifier
What is an Html Minifier?
HTML minification removes characters the browser does not need: comments, indentation, line breaks and redundant whitespace. Smaller HTML downloads faster and lets the browser start rendering sooner. It is also useful for HTML email, where some clients clip messages above a size limit.
How to use it
- Paste your HTML.
- Minify it.
- Compare the sizes and copy the result.
Example
Input:
<!-- Header -->
<header class='site'>
<h1> Welcome </h1>
</header>Output:
<header class='site'><h1>Welcome</h1></header>What gets removed
- HTML comments (conditional comments for old Outlook should be kept in emails).
- Whitespace between block-level tags.
- Runs of spaces collapsed to one inside text.
Why it matters
- Gmail clips emails whose HTML exceeds about 102 KB, hiding the rest behind a link. Minifying email templates helps stay under the limit.
- Server-rendered pages with heavy indentation can shrink by 10 to 25% before compression.
Cautions
- Whitespace between inline elements can be meaningful; removing it can join words, like turning Hello world split across two spans into Helloworld.
- Content inside
preandtextareamust not be changed. - Inline scripts with line comments can break if collapsed carelessly.
- Always enable gzip or Brotli on the server too; it saves far more than minification alone.
Frequently Asked Questions
How much does HTML minification save?
Typically 10 to 25 percent before compression, depending on how much indentation and how many comments the markup contains.
Why does Gmail clip my email?
Gmail clips messages whose HTML is larger than about 102 KB. Minifying the HTML reduces the size.
Can minification break my page?
Rarely, but removing whitespace between inline elements can join words, and pre content must be preserved. Check the result.
Should I keep comments in HTML emails?
Keep conditional comments used for Outlook, because they control rendering in those clients.