HTML Minifier

Paste a web page or a snippet and get a smaller version that renders the same. The minifier removes comments, collapses white space where it cannot be seen, shortens inline CSS, and leaves pre, textarea and script contents alone. You get the before and after size so you can see what it saved.

What you enter

What you get

How it works

  1. Paste your HTML into the box. It is processed in your browser and never uploaded.
  2. Choose what to do: remove comments, collapse white space, minify inline CSS in style tags and style attributes, and optionally drop the quotes around simple attribute values.
  3. Check the sizes. Conditional comments for old Internet Explorer are kept even when comments are removed.
  4. Copy the result or download it as an .html file.

Which white space is safe to remove

Browsers collapse runs of spaces, tabs and line breaks in text into a single space when they draw a page. That means most of the indentation in a source file never reaches the screen, and it is the first thing a minifier removes. What a minifier must not do is remove the one space that does show, such as the gap between two words that sit in different tags.

The rule this tool follows is simple. Next to block-level tags (div, p, ul, li, table, headings and similar) the space is invisible, so it is trimmed. Between or next to inline tags (a, span, b, em, img and similar), one space is kept. Non-breaking spaces are never collapsed, since they are there on purpose.

Comments, conditional comments and pre blocks

Comments never show on the page and are safe to drop, with one exception: conditional comments written for old versions of Internet Explorer look like comments but carry real instructions, so they are kept. Comments that explain your code to other developers should be in the source file, not the one you publish.

The pre and textarea elements preserve white space by definition. Collapsing it would change what a visitor sees or what a form sends. The minifier passes their contents through untouched, including any tags inside a pre element, and counts nested pre blocks so that it finds the right closing tag.

Where HTML size matters

The HTML document is the first thing a browser downloads, and the page cannot start drawing until it has the start of it. Trimming it helps, but only by the weight of the white space and comments, which is rarely the biggest cost on a page. Large images, web fonts and third party scripts usually matter more.

If your server compresses responses with gzip or Brotli, repeated white space already compresses to almost nothing, so the gain from minifying is smaller than the raw numbers suggest. Minifying still helps for pages served without compression and for HTML embedded in emails or other places where size limits are tight.

Tips

Frequently asked questions

What does an HTML minifier remove?

Comments, line breaks and indentation between tags, repeated spaces inside text, and the spaces inside a tag around its attributes. The text a visitor reads and the page structure are unchanged.

Will minifying change how my page looks?

It should not. White space between block elements such as div, p and li is invisible, so it can go entirely. White space between inline elements is visible as a gap, so one space is kept. Text inside pre, textarea, script and style is never touched.

What about JavaScript?

Script contents are left exactly as written, because shortening JavaScript safely needs a full parser and a mistake would break your page. Scripts of type JSON, such as structured data for search engines, do have their spaces removed.

How much will it save?

A page with deep indentation and many comments may shrink by a fifth or more. Take '<p> Hello world </p>': it becomes '<p>Hello world</p>', 18 bytes instead of 24, a saving of 25 percent. Real pages save less, because most of their size is text and attributes.

Is my code uploaded anywhere?

No. The minifier runs as code in your browser, so your HTML stays on your device.

Related: CSS minifier, HTML table generator, Website grader.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Free Tools

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap