HTML Minifier

Shrink HTML by removing comments and collapsing whitespace.

Free HTML minifier — remove comments and collapse whitespace between and inside tags while preserving pre, textarea, script and style content. Runs entirely in your browser, nothing is uploaded. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

Does it keep formatting inside pre and textarea?

Yes. The contents of pre, textarea, script and style tags are preserved exactly, because whitespace is significant there.

Minify HTML in your browser

Paste any markup to remove comments and collapse whitespace between and inside tags, producing a smaller file that downloads faster. It is handy for trimming the page weight of static pages, email templates, and embedded snippets.

Hand-authored HTML is often far larger than it needs to be: dozens of lines of indentation, developer comments left in, and blank lines between every tag. None of that reaches the user’s screen, but every character travels over the wire and adds to parse time. Minifying is the lowest-risk size reduction available because the output is semantically identical to the input.

How it works

The minifier strips standard HTML comments (<!-- ... -->) while keeping IE conditional comments that legacy pages may still rely on, then collapses runs of whitespace between and inside tags down to a single space or removes them. Crucially it leaves the contents of pre, textarea, script and style exactly as written, because spaces, tabs and newlines are meaningful in those elements. The result is functionally identical markup with the bulk of the layout whitespace gone, and the tool reports how many characters you saved.

Example

This formatted input:

<!-- nav -->
<ul>
  <li>Home</li>
  <li>About</li>
</ul>

minifies to:

<ul><li>Home</li><li>About</li></ul>

The comment and the indentation are gone, but the elements and their text are unchanged. Everything runs locally in your browser — nothing is uploaded.

Practical scenarios

Email templates — HTML email clients are picky, and email service providers sometimes impose message-size limits. Minifying a handwritten template before uploading it to your ESP trims a few kilobytes without touching the rendered layout or the inline CSS that those clients rely on.

Static site snippets — When you embed a generated HTML fragment in a CMS or a README, minifying first lets editors see the content as a single readable line rather than a blob of indented code.

Comparing diffs — If you export HTML from two different tools and want to compare the structure, minifying both strips cosmetic formatting differences so a diff highlights only meaningful changes.

Tips and edge cases

  • Inline elements and whitespace — A space between two <span> tags is visually significant (it is the word-gap between two words). The minifier preserves a single space in those positions, so your text does not run together. If you see unexpected merging, add an explicit &nbsp;.
  • Pair with the CSS and JS minifiers — This tool focuses on the HTML markup. Inline <style> and <script> blocks are preserved as-is; run the dedicated CSS minifier and JavaScript minifier on those separately for maximum savings.
  • Measure the saving — The tool shows the character count before and after. For heavily indented, comment-rich templates the reduction is typically in the range of 10–30% of total size; for auto-generated compact HTML it may be minimal, which tells you further savings need to come from image compression or script splitting instead.