Skip to content
trustedonlinetools

HTML Minifier

Paste formatted HTML and get a smaller version with comments stripped and whitespace collapsed — processed client-side so your markup stays private.

What Is HTML Minification and Why Does It Matter?

HTML minification removes characters that browsers do not need to render a page — comments, extra whitespace, redundant quotes, and optional closing tags. The result is a smaller file that transfers faster over the network and parses marginally quicker.

For pages served without gzip or brotli compression, minification can shave 10-30% off file size. Even with compression enabled, removing comments and collapsing whitespace still helps because the compressor has less redundant data to encode.

How It Works

This tool uses html-minifier-terser to strip comments, collapse whitespace, and optionally minify inline CSS and JavaScript — the rendered output in a browser is identical. It processes the document in a single pass, understanding HTML semantics to avoid breaking whitespace-sensitive elements.

Inline style attributes and style blocks are minified using clean-css rules, and inline script blocks are compressed with terser. Boolean attributes like disabled and checked are shortened to their attribute-only form, and redundant attribute quotes are removed where safe.

Privacy and Security

The minifier runs entirely in your browser — your HTML is never sent to any server. The html-minifier-terser library and its dependencies are bundled as client-side JavaScript, so processing happens locally in your browser tab.

You can safely minify internal templates, staging pages, or markup containing sensitive data without any network exposure. No analytics or telemetry is collected on the content you process.

Tips and Edge Cases

Minification removes all HTML comments. If your workflow relies on conditional comments (for legacy IE) or special comment markers (like build tool directives), document them separately or add them back after minifying.

Whitespace inside pre and textarea elements is never collapsed since doing so would change the visible output. Inline scripts and styles are also minified by default, which can occasionally surface issues if your JavaScript relies on Function.toString() or similar reflection patterns — though this is rare in practice.

Frequently asked questions

Does minifying HTML change what the browser renders?

No. The minifier only removes characters that do not affect rendering — comments, extra whitespace, and redundant syntax. The page looks and behaves identically after minification.

Are HTML comments always removed?

Yes. All standard comments are stripped. If you have conditional comments for legacy browsers or build-tool markers you need to keep, add them back after minifying or use a build pipeline that preserves specific patterns.

Does it minify inline CSS and JavaScript too?

Yes. Style blocks and attributes are processed with clean-css rules, and script blocks are compressed with terser. This gives you a single-pass reduction across all inline code without needing separate tools.

What about whitespace in pre or textarea tags?

The minifier detects whitespace-sensitive elements and leaves their content untouched. Collapsing whitespace inside a pre block would change visible output, so it is explicitly preserved.

How much smaller will my HTML get?

It depends on the original formatting. A well-commented, neatly indented file can shrink 15-30%. Already-compact markup with few comments will see smaller gains. The tool shows the before/after byte count so you can measure immediately.

Is there a file size limit?

No hard limit is enforced, but processing happens in your browser's main thread. Documents over a few MB may cause a brief pause. For typical page templates and components the result appears instantly.