Minify HTML
Strip comments and collapse whitespace, safely.
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
- Paste your HTML. A fragment or a whole document.
- Choose what to remove. Comments, whitespace and optionally attribute quotes.
- 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?
How much does minifying actually save?
Why are conditional comments kept?
Is removing attribute quotes safe?
Should I minify by hand or in a build step?
Last updated