Skip to content
Browser tool Runs locally

HTML Minifier

Remove unnecessary formatting whitespace from HTML while preserving meaningful content and behavior.

HTML input
0 chars
Minified HTML
Minified HTML will appear here.
Examples:

How to minify HTML

  1. Paste HTML in the input panel.
  2. Choose whether to preserve comments.
  3. Click Minify HTML.
  4. Copy or download.

What HTML minification does

  • Removes indentation and line breaks between block elements.
  • Collapses whitespace between inline elements.
  • Removes ordinary comments.
  • Preserves DOCTYPE, structure, and text content.

What happens to comments?

Ordinary comments are removed. Conditional comments, license markers, and SSI directives are preserved automatically.

HTML minification vs. gzip

Minification reduces source bytes; gzip is binary compression on the wire. They are complementary.

When HTML minification is useful

Minifying is worth doing before shipping a static page, email template, or any document whose size affects load time or storage - trimming indentation, line breaks, and comments reduces the bytes a browser or client has to download and parse, without changing what's rendered.

What gets removed safely

Indentation and line breaks between block-level elements are dropped, along with ordinary HTML comments that carry no functional meaning. Whitespace that's actually meaningful - inside text content, between inline elements, or within pre and textarea - is left alone so the rendered page doesn't shift.

Attributes and boolean attributes

Attribute values and their quotes are kept as-is rather than rewritten, and boolean attributes like disabled, checked, or required are left in their original written-out form. Minification focuses on removing bytes that don't affect parsing, not on restyling how attributes are expressed.

Test minified output before deploying

Minification is designed to preserve HTML semantics, but templates with embedded scripts, unusual whitespace-dependent styling, or non-standard markup can behave unexpectedly after any transformation. Preview a minified page or template in a real browser, not just the diff, before rolling it out.

Frequently asked questions

Does this HTML minifier upload my code?
No. Parsing and minification run entirely in your browser.
Does it remove HTML comments?
Yes, by default. Conditional comments, license markers, and SSI directives are preserved automatically.
Will minifying change how my page looks or behaves?
It shouldn't, since only formatting whitespace and safe-to-remove comments are stripped and the element structure, attributes, and text content are left intact. It's still worth previewing a minified page before deploying it, especially if it relies on unusual whitespace or embedded scripts.
What happens to attribute quoting and boolean attributes?
Attribute values keep their quotes, and boolean attributes such as disabled or checked are left as written rather than being rewritten to a shorthand form, since browsers already parse them the same way either way.
How much does minifying HTML actually save?
It depends on how much indentation and commenting the original file has; a heavily formatted template can shrink noticeably, while output that's already compact from a build tool sees a smaller reduction. Pairing minification with gzip or brotli compression on the server usually matters more for actual transfer size.

Related tools