HTML Minifier

Shorten an HTML fragment.

Use this tool

Result

The result appears in this panel after you run the tool.

About this tool

Tags are kept. Comments and space between tags are reduced.

Conditional comments and significant whitespace in pre are not specially preserved.

How to use it

  1. Open this page and provide the input it asks for.
  2. Set the options that are visible, then use Minify HTML.
  3. Read the result in the panel. Copy it or download it when a file is offered. The input stays in this browser.

Limitations

Gaps between tags shrink, structure stays unparsed

Comment regions are cut out, then tags are drawn together

Tags stay, and the gaps between them shrink. The minifier deletes each HTML comment, from the opening marker through the closing marker. It then deletes whitespace that sits between a closing angle bracket and the next opening angle bracket, so adjacent tags meet. Runs of two or more whitespace characters elsewhere become one space. The result is trimmed. Empty input is rejected. The page does not parse the markup into elements, so it does not execute scripts, and it also does not notice that a tag was never closed.

Because the pass is textual, a comment marker inside a script string or a style block can be removed if it looks like a comment. Double spaces in visible text become single spaces, including spaces you wanted in a paragraph or in preformatted text. The formatter, by contrast, leaves the interior of pre, textarea, script, and style untouched and only reflows ordinary text. This minifier has no such exception. A pretty indent is not available here.

What is not checked

Well-formedness is not required. A missing close tag stays missing. Attributes are not reordered and unknown attributes are not removed. Event-handler attributes remain in the text. If you needed those stripped, the markdown-to-HTML sanitizer is a different pipeline and it starts from markdown. This page starts from HTML text and returns shorter HTML text. It does not build a DOM and it does not pretty-print.

When the shorter file is the wrong file

A copyright comment, a conditional comment, and whitespace that a layout depended on are the usual losses. Significant spaces in mixed content can change how a sentence reads. If the document must stay readable in source control, use the formatter. If the document is a production snippet and you have compared the result, the squeeze is the point. The XML minifier uses the same substitutions on XML text. The HTML page is the one whose output type is HTML.

Privacy

Your input is processed in your browser and is not uploaded to UtilChain. File names, text, and results are not sent to analytics.