Free Converter

HTML Minifier

Minify and compress HTML code instantly in your browser. Remove comments, collapse whitespace, and reduce file size. Free and private.

Drag & Drop an HTML file here

Supports .html and .htm files. Or paste your HTML above.

Or

About HTML Minification

HTML minification strips unnecessary characters from a webpage's source — whitespace between tags, comments, redundant quotes, optional closing tags — to reduce file size without changing how the page renders. The savings are modest per page (typically 10–30%) but compound across many requests, particularly for static sites or pages served without dynamic compression.

This minifier removes whitespace between block-level elements, collapses runs of whitespace inside non-significant text, strips HTML comments (except IE conditional comments), removes redundant attribute quotes where allowed by the HTML5 spec, and elides optional closing tags (</p>, </li>) where the spec permits. The result renders identically to the source in every browser.

Minification is most useful when paired with gzip or Brotli compression at the server level. Compression already removes much of the savings minification produces, but the two combined still beat compression alone — particularly for high-traffic sites where bandwidth costs matter.

Why Minify HTML

Smaller HTML loads faster, especially on slower connections and mobile networks. Page weight directly affects Core Web Vitals — Largest Contentful Paint and Time to First Byte both improve when the server returns less HTML to parse. For sites where SEO ranking depends on Core Web Vitals scores, minification is a measurable improvement.

Minified HTML also reduces bandwidth costs at scale. A site serving a million pages a day with 10 KB savings per page saves 10 GB of egress daily. The impact compounds for static sites served from CDNs that bill by data transfer.

How to Minify HTML

Paste HTML, get the minified version.

  1. Add HTML input: Paste HTML source into the input area or drop a .html file. The minifier accepts any valid HTML5 markup.
  2. Choose options: Defaults remove comments and collapse whitespace; you can disable individual transformations if you need to preserve specific elements (e.g., keep comments for documentation).
  3. Minify: The minifier walks the HTML token stream, applying each enabled transformation. Output is functionally identical HTML with reduced size.
  4. Copy or download: Use the result as the served HTML. Confirm the page renders correctly in target browsers before deploying.

Common Use Cases

Technical Details

The minifier processes HTML token by token. Whitespace between block-level elements (<div>, <p>, <ul>) is removed because it does not affect rendering. Whitespace inside inline contexts (<span>, <a>, text content) is preserved because it can affect rendering.

Comments are stripped by default but conditional comments (<!--[if IE]>) are preserved. Attribute quotes are removed where the HTML5 parser allows — single-word attribute values without spaces or special characters can omit quotes.

Optional closing tags are elided per the HTML5 spec: </p>, </li>, </td>, and a few others can be omitted when followed by a sibling that implies their close. This is unusual to read but valid HTML5 that browsers parse identically.

Best Practices

Frequently Asked Questions

How much can minification reduce file size?
Typically 10–30% of the source size, though it varies by content. Pages with heavy comments or generous whitespace see larger savings; tight pages see less. Combined with gzip the marginal savings are smaller.
Will minification break my page?
Properly implemented minification preserves rendering. Edge cases involve inline scripts, CSS, and HTML where whitespace is intentionally significant. Test in your browsers before deploying widely.
Does it minify CSS and JavaScript inside HTML?
Inline CSS and JavaScript can be minified by separate minifiers. This tool focuses on HTML structure; pair with cssMinifier and jsMinifier for full optimization.
Are HTML comments preserved?
By default, no. Strip comments option removes them. IE conditional comments are preserved by default since they affect old-IE rendering.
Are optional closing tags safe to remove?
Yes per HTML5 spec, though the result is harder to read. Some teams disable this transformation for clarity, accepting the slight size penalty.
Is my HTML uploaded to a server?
No. The minifier runs in your browser.
How does this compare to html-minifier-terser?
html-minifier-terser is the canonical Node.js HTML minifier and produces slightly more aggressive results. This tool covers the same transformations for browser-side use without a build setup.
Should I minify always or selectively?
Always for production. Never for source code in version control; readable HTML in source is essential for maintenance.