RSRobince Studio

HTML Minifier

Make an HTML document smaller by removing comments and collapsing unnecessary whitespace. The minifier is deliberately conservative: it leaves the contents of pre, textarea, script and style exactly as written and keeps spaces that affect inline text.

Runs in your browser. Your files are never uploaded.

Loading HTML Minifier…

How to use HTML Minifier

  1. Paste your HTML into the input box.
  2. Decide whether to keep comments and whether to remove all space between tags.
  3. Read the savings summary under the boxes.
  4. Copy the minified HTML and test it in a browser.

Why minify HTML

HTML is often the first file a browser requests, and everything else waits on it. Trimming whitespace and comments reduces transfer size, which can help the first byte arrive and the page start parsing a little sooner. For templates generated by a CMS, indentation and developer comments can account for a surprising share of the file.

Savings from HTML alone tend to be modest next to images, scripts and fonts, so treat it as a tidy-up rather than a major speed-up. Server-side gzip or Brotli typically removes much of the repetition that whitespace creates, so the real gain on the wire is smaller than the raw percentage suggests.

How whitespace is handled

Browsers collapse runs of whitespace in normal text into a single space, so turning several spaces and newlines into one is safe. Whitespace that sits between two block-level elements, such as paragraphs or list items, has no visible effect and is removed entirely. Whitespace between inline elements may be rendered as a visible gap, so the tool keeps one space there.

Text inside pre and textarea is whitespace-sensitive by design. Script and style contents may include template literals or comments that depend on line breaks. For these reasons they are copied verbatim.

  • Comments are removed unless you choose to keep them.
  • Spaces inside attribute values are not altered.
  • Doctype declarations are preserved.

Limits and good practice

This is a text-level tool, not a full HTML parser, so very unusual markup such as unclosed tags inside attribute values may not be handled perfectly. Always compare the rendered page before and after, especially for pages with inline-block layouts or text styled with white-space rules in CSS.

Keep your readable source under version control, publish the minified copy, and rebuild it whenever the source changes. Your markup is processed locally in the browser and is never uploaded.

Why use this html minifier tool

  • Protected blocks. The content of pre, textarea, script and style elements is never changed.
  • Inline-aware spacing. Space between inline tags such as bold and italic is kept by default, so words do not run together.
  • Conditional comments kept. Internet Explorer conditional comments are preserved even when other comments are removed.
  • Savings report. Original size, new size and the percentage saved.

Frequently asked questions

Can minifying break my page?

It is designed not to, but whitespace in HTML sometimes matters. In the default mode a space between two inline elements is preserved. The aggressive option removes it, so test any page that places inline elements side by side before using that setting.

Does it minify inline CSS and JavaScript?

No. Script and style blocks are copied as they are. Run those through the CSS and JavaScript minifiers separately and paste the compact result back if you want extra savings.

Does it remove optional tags or attribute quotes?

No. Those transformations are valid in HTML but they reduce readability and can interact badly with some tools, so the tool leaves your markup structure alone.

More free tools