Skip to content

Formatters & Code

HTML Minifier

Collapse whitespace, drop comments — slim HTML.

Runs in your browser
Minified · 147 chars (31.0% saved)
<!doctype html><html lang="en"><head><title>AnytimeConvert</title></head><body><main><h1>Hello</h1><p>This is a demo page.</p></main></body></html>

Understanding HTML minification

Whitespace mostly, but watch the inline content.

What HTML minification can safely strip, what it must preserve, and the inline-script and inline-style cases that need separate minifiers.

What's safe to remove.

Whitespace between tags (mostly). HTML comments (<!-- ... -->), unless they're conditional comments for legacy IE (those are 2026-irrelevant but might still appear in old templates). Optional closing tags — </li>, </p> can be omitted before certain following tags by the HTML5 spec. Default attribute values: type="text" on an input is the default; the attribute can be dropped. Boolean attribute values: disabled="" becomes just disabled.

The whitespace gotcha.

Whitespace inside <pre> tags is significant — never strip it. Whitespace between inline elements (span, a, strong) renders as a single space; stripping it produces visible differences. Whitespace around block elements (div, p) is usually safe to remove. A minifier that doesn't distinguish these classes produces output that renders differently from the source — a subtle regression.

Inline scripts and styles.

A page with <script>...</script> blocks needs a JS minifier to handle the script content; same for <style>...</style> and CSS. Good HTML minifiers chain these — html-minifier-terser composes html-minifier + Terser + clean-css. A minifier that skips this leaves the inline content unminified, which defeats half the point.

A worked minify.

Input: <!doctype html> <html> <head> <title>Hi</title> <meta charset="utf-8" /> </head> <body> <p>Hello there.</p> </body> </html> Output: <!doctype html><title>Hi</title><meta charset=utf-8><p>Hello there.</p>. The HTML5 parser fills in missing <html>, <head>, <body> tags automatically; the attribute quotes drop when unambiguous; the closing </p> isn't required before end of document.

HTML5 lets you skip a lot

implicit tags + unquoted attributes + optional closes

Result is valid HTML5; parsers fill in the missing structure.

150 bytes → ~85 bytes

= 40 % reduction

Modern frameworks already do this.

Next.js, Astro, SvelteKit, Nuxt all minify HTML in production builds by default. The standalone HTML minifier is for projects that build HTML directly — static site generators that don't auto-minify, hand-built marketing pages, email templates (where every byte counts because the recipient's email client might truncate large messages). Most application authors never run a separate HTML minifier; the framework does it.

The tiny risk profile.

HTML minifiers occasionally break things. The most common: aggressive attribute-value unquoting that fails when the value contains a space or special character; whitespace removal inside <textarea>that changes form behaviour; comment removal that strips conditional comments still in use (rare in 2026). A reasonable build pipeline runs smoke tests after minification — render the minified HTML, compare visual and behavioural output to source. Tools that ship without this safety net surprise users occasionally.

Frequently asked questions

Quick answers.

Will minification break my website?

Standard minification only removes redundant whitespace and comments which does not affect page layout. However, if your CSS relies on `display: inline-block` without specific margins, removing whitespace between elements can slightly shift their horizontal positioning.

Does this tool remove script or style tags?

No. The minifier collapses whitespace within `<script>` and `<style>` tags if they contain standard JS or CSS, but it will not remove the tags themselves or alter your logic.

Is my source code private?

Yes. The minification logic is executed entirely via JavaScript in your client browser. Your HTML is never uploaded to our infrastructure.

What is the difference between compressing and minifying?

Minification removes source code characters to reduce file size, while compression (like Gzip or Brotli) happens at the server level to shrink the data during transit. For best performance, you should use both.

People also search for

Related tools

More in this room.

See all in Formatters & Code