DevKits

HTML Minifier — Compress HTML Online for Smaller Page Size

Minify HTML by removing comments, collapsing whitespace, and stripping optional attribute quotes and void-element slashes. Reports byte savings. Preserves IE conditional comments and preformatted <pre> / <textarea> / <script> / <style> content. 100% local.

Last updated:

Comments

Paste HTML to strip comments, collapse whitespace, and remove optional slashes. Reports byte savings side-by-side with the original size. Preserves IE conditional comments and the contents of <pre>, <textarea>, <script>, and <style> so functionality and layout stay intact.

Options:

Original

394 B

Minified

302 B

Saved

23%

394 chars · 20 lines

Need to go the other way? HTML Beautify →

What is HTML Minifier?

HTML minification is the process of removing every byte from a page that doesn't affect what the browser renders. That means stripping HTML comments (except conditional comments), collapsing runs of whitespace to a single space (or nothing between block-level tags), removing optional attribute quotes when values are unambiguous, and eliminating the self-closing slash on void elements like <br /> and <img />. On modern sites, HTML minification typically saves 15–35% on hand-written pages and 40%+ on framework-generated output — savings that add up quickly when combined with gzip / brotli compression, cache-friendly headers, and modern CDN delivery. Every major static site generator (Astro, Next.js, Hugo, Eleventy) minifies HTML in production; this tool lets you inspect exactly what a minifier would output before wiring one into your build pipeline.

How to minify HTML online

  1. 1Paste your HTML into the input pane.
  2. 2Adjust options: remove comments (default on), collapse whitespace (default on), remove void-element slashes (default on), remove attribute quotes (opt-in — more aggressive).
  3. 3The output pane shows the minified HTML; the header reports original size, minified size, and % saved.
  4. 4Copy the output and use it as your build artifact — or wire this same logic into your pipeline.

Use Cases

Shrink static site output

Even after Astro / Next.js pre-render, generated HTML often has extra newlines and indentation. Minify to shave 10–30% off first paint.

Inline HTML in email templates

Email clients strip line breaks unpredictably and don't gzip. Pre-minified HTML avoids surprises.

Embed HTML in a single-line context

When embedding HTML in a JSON string / SQL insert / Markdown code fence, minifying first removes accidental line breaks that would need escaping.

See what a production build produces

Before shipping, run your source template through this tool to sanity-check that minification doesn't break your layout — especially around <pre> / <textarea>.

Key Concepts

Void element
An HTML element that cannot have content and doesn't need a closing tag: area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr. The self-closing slash <br /> is optional in HTML5.
Preformatted element
Elements whose whitespace is preserved by the browser: <pre>, <textarea>, and (functionally) <script> and <style>. Minifiers must leave their contents alone.

Tips & Best Practices

  • ▸Never minify inside <pre>, <textarea>, <script>, or <style> — whitespace inside those is meaningful. This tool preserves them automatically.
  • ▸Keep IE conditional comments (<!--[if IE]> ... <![endif]-->) — they're meaningful markup for legacy IE support, not just comments.
  • ▸'Remove attribute quotes' is the most aggressive option — it saves a few bytes per attribute but reduces readability. Skip it unless every byte matters.
  • ▸For maximum production savings, combine minification with gzip / brotli on the wire — order-of-magnitude effects, not additive.

Frequently Asked Questions

What does the minifier remove?

By default: HTML comments (except IE conditional comments), redundant whitespace between tags, and optional self-closing slashes on void elements (<br/> → <br>). You can also opt in to attribute-quote stripping when the value is unambiguous.

Does it preserve <pre>, <textarea>, and <script> content?

Yes. Any content inside <pre>, <textarea>, <script>, or <style> is preserved byte-for-byte — collapsing whitespace inside those would break rendering / functionality.

How much can I save?

Typical hand-written HTML shrinks by 15–35%. Framework-generated HTML with lots of indentation and comments can shrink by 40%+. Combined with gzip / brotli, minification usually adds another 3–8% on the wire.

Are IE conditional comments preserved?

Yes. Any comment matching <!--[if ...]> ... <![endif]--> is kept intact — these are meaningful markup, not just documentation.

Is my HTML uploaded anywhere?

No. Minification runs entirely in your browser.

Try Next

Meta Tag Preview

Preview how your page will appear in Google search results and social share cards on Facebook, Twitter/X, and LinkedIn. Parses <title>, meta description, canonical, and full Open Graph / Twitter Card tags with diagnostics. 100% local.

Related Tools

Reference & Guides