Orpheus

Minify HTML

Strip comments and collapse whitespace, safely.

Options
Remove comments
Collapse whitespace
Remove quotes from simple attributes
Result

Everything is processed in this tab. Nothing you paste is sent anywhere.

Every tool runs entirely in your browser. Your files are never uploaded to a server.

Minifying HTML removes comments and unnecessary whitespace. It is only safe where whitespace has no meaning — inside pre and textarea, and between inline elements, a space is content rather than formatting.

How to use HTML Minifier

  1. Paste your HTML. A fragment or a whole document.
  2. Choose what to remove. Comments, whitespace and optionally attribute quotes.
  3. Copy the result. The size saved is shown as bytes and a percentage.

About minifying HTML

Minifying HTML is mostly about deciding which whitespace is formatting and which is content, and the answer is not uniform across the document. Inside a pre or textarea element every space and newline is displayed exactly as written, so touching them changes what the user sees. Inside script and style the content is not HTML at all and collapsing it can alter behaviour — a line comment in JavaScript followed by a collapsed newline comments out the rest of the file. Those four elements are lifted out before anything happens and put back afterwards. The subtler case is whitespace between tags. Between two block-level elements it renders as nothing and can be removed freely. Between inline elements it renders as a space that the sentence depends on, so collapsing it turns "one two" into "onetwo" — a failure that is invisible in the markup and obvious on the page. A minifier that treats all inter-tag whitespace the same way will produce that bug eventually, which is why the rule here is applied only around elements that are block-level by default. It is worth being realistic about the benefit. Minification typically removes ten to twenty percent of raw bytes, but compression already handles repeated whitespace extremely well, so the saving over a gzipped or Brotli-compressed connection is usually in the low single digits. That is worth taking in a build step where it costs nothing ongoing, and it is not a reason to make source unreadable.

Frequently asked questions

Can minifying HTML break a page?
Yes, in two specific ways. Removing whitespace inside a pre or textarea changes what is displayed, and removing it between inline elements deletes a real space — turning "one two" into "onetwo". Both are handled here, which is why the tool is more conservative than a plain whitespace strip.
How much does minifying actually save?
Typically 10 to 20% of raw size, and far less after compression — gzip and Brotli already encode repeated whitespace very efficiently. On a compressed connection the real saving is often 1 to 3%, which is worth having and is not transformative.
Why are conditional comments kept?
Because a downlevel-revealed conditional comment contains markup that some browsers actually render. It looks like a comment and is not, so deleting it removes real content from the page.
Is removing attribute quotes safe?
Only when the value contains no spaces, quotes, equals signs or backticks. It is off by default because the saving is a couple of bytes per attribute and the failure mode — an attribute silently swallowing what follows it — is severe.
Should I minify by hand or in a build step?
In a build step, always, so the source stays readable and the output is regenerated automatically. This tool is for one-off cases: an email template, an embed snippet, or checking what a minifier would do before adding one.

Last updated