Compress HTML by removing whitespace and comments

Minify HTML by removing safe formatting bytes while preserving the DOM and text content.

freeworks offlinenothing uploaded
ToolHTML Minify
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

HTML is tokenized while comments and formatting whitespace are removed where they are not text; attributes are serialized safely and raw-text elements remain protected. Element order and document structure stay unchanged.

  • Formatting removal is safer than optional-tag rewriting.
  • Raw-text and preformatted content remain protected.

Worked example

Compress HTML with comments
Remove whitespace, line breaks, and comments from formatted HTML
Input
											<div>
  <!-- navigation -->
  <nav>
    <a href="/">Home</a>
  </nav>
</div>
										
Output
												<div><nav><a href="/">Home</a></nav></div>
											

When to use this

Production pages, static-site builds, and markup snapshots minify HTML.

Edge cases

  • Whitespace in pre, textarea, and script is data.
  • A > inside a quoted attribute is not a tag close.
  • Removing a space between unquoted attributes can merge tokens.

References