Skip to content
Toolew.com

HTML Minifier

Strip comments, whitespace and optional attribute quotes from HTML, entirely in your browser using html-minifier-terser.

Runs in your browser. Your data is not uploaded.
Loading tool…

This guide is not yet available in your language and is shown in English.

Tool guide

What this tool does

HTML Minifier removes comments, collapses non-essential whitespace, and optionally strips attribute quotes from HTML markup, using html-minifier-terser (the same engine many build tools rely on) entirely client-side, with a before/after size comparison.

Reducing an HTML page or snippet’s size for faster delivery usually happens through a build pipeline, but for a quick one-off snippet, running it through a minifier directly avoids setting up tooling.

This tool uses html-minifier-terser, the same minification engine many popular build tools rely on, running entirely in your browser, with options for removing comments, collapsing whitespace and (optionally) stripping attribute quotes.

How to use HTML Minifier

  1. Paste your HTML.
  2. Toggle which optimisations to apply (comments, whitespace, attribute quotes).
  3. Review the before/after size comparison.
  4. Copy or download the minified output.

Tips for better results

  • Removing attribute quotes is only safe for attribute values with no spaces or special characters, this option can produce broken markup if an attribute value genuinely needs its quotes, leave it off unless you’re sure.
  • Collapsing whitespace removes extra line breaks and indentation between tags, this can occasionally affect the visible rendering of inline elements where whitespace is meaningful (like text with intentional spaces between inline <span> tags), check the result visually if that applies to your markup.
  • Minified HTML is much harder to read or debug directly, keep your original, formatted source as the file you actually edit.
  • For most real projects, HTML minification happens automatically as part of a build or templating pipeline; this tool is most useful for a quick one-off snippet or static page fragment.

Common use cases

  • Quickly minifying a small HTML snippet or static page fragment without setting up build tooling.
  • Reducing the size of HTML pasted into a context with a character limit.
  • Stripping comments from HTML before sharing it publicly.
  • Checking how much of a page’s size comes from comments and formatting versus actual content.

Common mistakes to avoid

  • Removing attribute quotes on values that contain spaces or special characters, which produces genuinely broken markup; only enable that option for simple, space-free attribute values.
  • Collapsing whitespace on markup where inline spacing between elements is visually meaningful, occasionally affecting the rendered layout in subtle ways, check the visual result if your markup relies on specific inline whitespace.
  • Editing the minified output directly going forward instead of keeping a readable source; always maintain your original formatted HTML and re-minify from that each time.

Frequently asked questions

Is it safe to remove attribute quotes?

Only for attribute values with no spaces or special characters; values that need quoting to stay intact will produce broken markup if this option strips them, leave it off unless you’re confident your values are simple.

Can collapsing whitespace affect the page’s appearance?

Occasionally, yes, if inline elements rely on specific whitespace between tags for visible spacing, collapsing it can subtly change the rendered layout; check the result visually for markup like that.

Does this validate my HTML for errors?

No, it only compresses whatever markup you provide; it doesn’t check for or fix invalid HTML, existing errors will persist in the minified output.

Is my HTML uploaded anywhere?

No, minification happens entirely in your browser using html-minifier-terser; nothing is transmitted anywhere.

Feedback & suggestions

Help us improve HTML Minifier. We read every message.

Rating (optional)
Necessary
Required for security, language and theme preferences. Always on.