Skip to content
Back

HTML Minifier

Remove comments and extra whitespace from HTML, and minify inline CSS.

Inline JavaScript isn’t minified — only the blank space before and after each script’s code is trimmed, because minifying JS safely needs a real parser.

Shrink HTML without changing how the page looks

HTML Minifier strips out the parts of your markup that browsers don’t need: comments, indentation, line breaks and the extra spaces between tags. The page should render the same — the file is just smaller to send.

The defaults are deliberately cautious. Runs of whitespace become a single space, and whitespace is only removed completely next to block-level tags such as div, p, li or table cells, where it has no visible effect. Your markup is processed in the browser tab and isn’t sent to a server.

How to minify HTML

  1. Paste a full document or just a fragment into the HTML input box.
  2. Choose the options you want. Remove comments, Collapse whitespace and Minify inline <style> CSS are on by default.
  3. Leave “Remove all space between tags” off unless you’ve checked the result — it can glue inline elements like links or bold text together.
  4. Click Minify HTML. If you change an option afterwards, the output updates by itself.
  5. Use Copy result to grab the minified code, or Clear to start again.

Reading the size savings

Three figures appear after minifying: Original, Minified and Saved. Sizes are measured in bytes as UTF-8, so accented letters and emoji count as more than one byte, just as they do on the server.

Hand-written, heavily indented HTML usually shrinks the most. Markup that’s already compact, or that is mostly inline JavaScript, will show a small saving because scripts are not minified.

Good times to minify

  • Static pages: trim a hand-coded landing page or email-friendly HTML before you upload it.
  • Embeds and snippets: tidy a widget or template fragment you’re pasting into a CMS field with a character limit.
  • Comparing builds: see how much of a page’s weight is just formatting and comments.
  • Stripping notes: remove developer comments before sharing markup with a client.

Avoiding layout surprises

  • If your CSS turns list items or other block tags into inline-block, the gaps between them come from whitespace. Minifying can close those gaps — compare the page before and after.
  • Keep an unminified copy as your source. Minified HTML is hard to edit by hand.
  • Minifying helps, but images are usually the heavier part of a page. The Image Compressor often saves far more bytes.
  • Once the page is lean, give it a proper title, description and share image with the Meta Tag Generator.

HTML Minifier: common questions

Will minifying break my page?

With the default options it shouldn’t: spaces between inline elements are kept as a single space, and only whitespace next to block-level tags is dropped. The riskier “Remove all space between tags” option is off unless you tick it.

Does it change content inside <pre> or <textarea>?

No. The contents of <pre> and <textarea> are left exactly as written, including any comments inside them, because spacing there is visible.

Does it minify JavaScript too?

No. Inline <script> code is kept as written (only leading and trailing whitespace is trimmed), because shrinking JavaScript safely needs a full parser. Inline <style> blocks are minified unless you turn that option off; style="" attributes are left alone.

Are conditional comments removed?

Old Internet Explorer conditional comments (<!--[if IE]>…) are kept even when Remove comments is on, since they contain markup. All other comments are removed.

Does minified HTML help SEO?

Indirectly. A smaller file downloads a little faster, which helps page speed, but it won’t change rankings on its own. The free SEO tools overview covers what else is worth checking.