HTML Minifier

Removes comments and redundant whitespace from HTML while keeping visible text and inline spacing intact. Embedded CSS, JavaScript and JSON-LD blocks are minified in the same pass.

The output will appear here.
Advertisement icyabmod — admin panel included: update your website yourself, no code

How HTML Minifier works

Removes comments and redundant whitespace from HTML while keeping visible text and inline spacing intact. Embedded CSS, JavaScript and JSON-LD blocks are minified in the same pass.

Input HTML
Output Minified HTML
Works done 5,302

How to use it

Paste a page or template and this tool will minify HTML by removing comments, indentation and repeated whitespace, so the same markup ships in fewer bytes. It is careful about the spaces that matter: text and gaps between inline elements stay readable, and pre and textarea content is left exactly as written. Embedded <style>, <script> and JSON-LD blocks are compacted in the same pass, all inside your browser.

How to minify HTML here

  1. Paste the final, rendered HTML into the input box rather than a server-side template.
  2. Run the minifier with the "Run tool" button, or press Ctrl + Enter to do the same.
  3. Compare the size shown under the output with your original.
  4. Copy or download the result, then load the page once in a browser before deploying it.

What gets removed and what is protected

  • Removed: regular comments, line breaks, indentation and runs of spaces. Whitespace next to block-level tags such as div, li or table disappears entirely.
  • Collapsed, not removed: whitespace between inline elements and inside text shrinks to a single space, so words never run together.
  • Tidied: extra spaces inside tags, so <a href = "/"> becomes <a href="/">. Quoted attribute values are not modified.
  • Kept verbatim: pre and textarea contents, non-breaking spaces, conditional comments such as <!--[if lt IE 9]> and comments starting with <!--!.
  • Minified as code: inline CSS, inline JavaScript (comments and spacing only, no renaming) and application/ld+json structured data. Template scripts such as text/template are left alone, and a block that cannot be parsed is kept as it was.

A before and after you can check

Take a small product snippet written across several lines: a comment <!-- sale price -->, then <div class = "price">, then an indented <span>$49</span> <s>$65</s>, then the closing </div>. The minified version is <div class="price"><span>$49</span> <s>$65</s></div>. The comment and indentation are gone, the attribute is tidied, and the single space between the two prices survives because it is visible on screen. A tool that removed it would print "$49$65".

How much you save depends entirely on the source. In our own test, a 738-character landing page snippet with comments, indentation and an embedded stylesheet came out at 591 characters. Markup that is already compact will shrink far less.

Edge cases worth a second look

SituationWhat can happenWhat to do
Boxes laid out with display: inline-blockThe line break between two div tags rendered as a small gap; once removed, the boxes touchCreate the spacing with gap or margin
white-space: pre on a non-pre elementIts spacing is collapsed like any other textWrap preformatted text in a real pre
Server-side templatesTemplate tags may not parse as HTMLMinify the rendered output instead
Comments used as markers by editors or pluginsThe markers are deletedMinify only what is served, never content you will edit again

Minification and compression

Minifying does not replace gzip or Brotli on the server; the two stack. Compression already squeezes repeated whitespace well, so the difference over the wire is smaller than the raw numbers suggest. Minification still pays off where compression is missing or limited: single-page landing pages full of inline code, HTML snippets stored in databases, and HTML email, where some clients are commonly reported to clip messages above roughly 100 KB. The trade-offs are covered in what is minification.

Privacy and related tools

The minifier is plain JavaScript running in your tab, so the markup you paste is not sent to the server; only an anonymous usage counter is incremented. To make a minified page readable again, use the HTML beautifier. Standalone scripts can go through the JavaScript minifier, and the rest of the toolbox is under developer tools.

Advertisement Kelivo — a word game by icyabmod, on Google Play and the App Store

Frequently asked questions

In most cases it will not, because the tool only removes whitespace and comments that browsers ignore anyway, and it keeps spaces between inline elements. Layout changes happen in two known situations: inline-block elements whose spacing came from line breaks in the source, and elements that use white-space: pre without being a pre tag. Load the minified page once before deploying and both are easy to spot.

No. It deliberately avoids risky rewrites such as dropping closing tags, removing quotes around attribute values, collapsing boolean attributes or deleting default attributes. Those tricks save a few more bytes but can change how a page parses, especially when markup is later processed by other tools. The output is still normal, readable-by-machines HTML that any parser handles the same way as your source.

Search engines read minified and formatted HTML the same way, so minification has no direct ranking effect. The indirect benefit is speed: fewer bytes can mean a slightly faster first render, especially on slow connections or for pages with a lot of inline code. For most sites, image optimization, caching and server compression have a much bigger impact than HTML whitespace.

Yes, and it is one of the better use cases. Email templates tend to be long and heavily indented because they are built with nested tables, and some email clients are known to truncate large messages. The minifier keeps inline styles intact and leaves visible spacing alone. Always send a test message to a few clients afterwards, since email rendering is less forgiving than browsers.