Home/Tools/Minifiers/HTML Minifier

HTML Minifier

Minifiers

Minify and compress HTML code to reduce file size.

⚡ Instant🔒 Private, in your browser🆓 Free, no sign-up👥 For developers
Your data never leaves your browser. We do not store inputs.

What HTML Minifier does

The HTML Minifier removes comments and collapses the whitespace HTML does not need, so a page or email template weighs less before it ships. Paste your markup and get a compact version back, with the size saved shown in bytes. The contents of pre, textarea and script elements and your quoted attribute values are left exactly as written, and everything runs in your browser.

FV
Reviewed by the FreeToolsVerse team · Last updated · How we check our tools

Features and benefits

  • Removes comments and collapses whitespace, keeping one space between inline elements so words do not run together
  • Leaves pre, textarea and script contents and quoted attribute values exactly as written
  • Minifies style blocks by default, with a checkbox to switch that off
  • Shows the saving in bytes and keeps conditional comments

How to use HTML Minifier

  1. Paste your HTML markup into the input box
  2. Choose whether to remove comments and minify style blocks
  3. Click Minify and check the before and after size
  4. Copy or download the minified HTML, then open it in a browser to confirm it looks the same

Who should use it

Made for developers. Typical uses:

  • Shrinking a static landing page's HTML before deploying it
  • Compacting an email template's markup to reduce weight
  • Cleaning up HTML exported from a page builder before publishing

Example

A 179-byte snippet with a comment, a heading, a paragraph with bold and italic text, a pre block and a style block minifies to 139 bytes, about 22% smaller. The comment disappears, the style block becomes .a{color:red}, the space between the bold and italic words stays, and the pre block keeps its indentation.

Limitations and accuracy

It works on one pasted document and does not fix invalid markup or remove optional tags. Layouts that depend on the gaps between inline-block elements can shift slightly, so always check the page. The saving shown is raw size; servers usually compress HTML in transit anyway.

Accuracy: Output is tested to keep behaviour unchanged. Keep your original files and test the minified version before you deploy it.

Expert Tip

If a row of inline-block elements looks different after minifying, give the elements explicit margins instead of relying on the whitespace between tags.

Frequently asked questions

Will minifying break my page's layout?
It should not, because only whitespace and comments that do not render are removed. One space is kept between inline elements such as bold and italic text, and the contents of pre and textarea elements are untouched. Still, open the minified page in a browser before you deploy it, because unusual markup, such as layouts that depend on the spaces between inline-block elements, can look different.
Does it minify inline CSS and JavaScript too?
Style blocks are minified by default, and you can switch that off with the checkbox. Script contents are left exactly as written, so use the JavaScript Minifier for those if you want them compacted.
Is it free to use?
Yes, completely free.
Is my HTML uploaded to a server?
No, minification runs entirely in your browser.
Can I undo the minification?
The minifier doesn't overwrite your original — keep your source HTML and only deploy the minified copy, so you can always go back to the readable version.

HTML Minifier: the complete guide

What the minifier does

The HTML Minifier makes a page or email template smaller by removing comments and collapsing whitespace. You paste the markup, choose whether to remove comments and whether to minify style blocks, press Minify, and read the size before and after. The result can be copied or downloaded as minified.html. It runs in your browser and the markup is not uploaded.

A worked example

A 179-byte snippet contains a page comment, a div with a heading, a paragraph with bold and italic text, a pre block with two indented lines, and a style block. The minifier returns 139 bytes, a saving of about 22 percent: the comment is removed, the whitespace between block elements such as div, h2, p and pre is deleted, the style block becomes .a{color:red}, and a single space is kept between the bold and italic elements so the words do not run together. The pre block is left exactly as written, including its two leading spaces on the first line and four on the second.

What is protected

Whitespace is meaningful in some places in HTML, so the tool is careful. The contents of pre, textarea and script elements are left exactly as written, and quoted attribute values are not changed. A single space is kept between inline elements, because removing it would join words. Conditional comments used for old versions of Internet Explorer are kept when comment removal is on. The tool does not remove optional closing tags, quotes around attributes or other things that are valid but change how the markup looks to a human reader.

When the layout might change

Most pages look identical after minifying, but layouts that rely on the whitespace between inline-block elements can shift. A row of inline-block buttons, for example, has small gaps made by the spaces between tags. After collapsing, one space remains, and between block-level elements none does. Always open the minified page before you publish it. If a gap changes, give the elements explicit margins instead of relying on spaces.

Inline CSS and JavaScript

By default, the contents of style blocks are minified too. Switch the checkbox off if you want them untouched. Script contents are always left as written, so run scripts through the JavaScript Minifier and stylesheets through the CSS Minifier separately. To make minified HTML readable again, use the HTML Formatter. Compare the savings with the other things that slow a page, such as large images, which the guide to compressing images for faster websites covers, and see how to minify CSS, JavaScript and HTML for the full picture.

Limits

The tool works on one pasted document. It does not fix invalid markup, so check the HTML with the HTML Validator first. The saving shown is raw size, and servers usually compress HTML in transit anyway, so the difference over the network is smaller than the figure suggests. Keep your original markup as the version you edit.

Learning resources

Explore more in Minifiers, read the guides and articles, or see how we test our tools.

Share This Tool