HTML Minify

Minify HTML by removing comments and extra whitespace.

Local Your input is processed locally in your browser. Found a problem? Report an issue

What HTML Minify does

HTML Minify removes comments, removes whitespace between tags and collapses runs of spaces, to reduce the size of a page or template. It is a text-level minifier for simple markup, not a build-tool replacement.

HTML Minify examples

The built-in sample

Input

<!-- page header -->
<div>
  <h1>Hello</h1>
  <p>Some   <b>text</b></p>
</div>

Output

<div><h1>Hello</h1><p>Some <b>text</b></p></div>

This is the input that the Load sample button fills in.

Comments, indentation and runs of spaces

Input

<!-- header -->
<div>
  <p>Hello   world</p>
  <pre>a
   b</pre>
</div>

Output

<div><p>Hello world</p><pre>a b</pre></div>

The comment and the whitespace between tags are removed and the three spaces in the paragraph become one. Note what happened inside pre: its line break and indentation were collapsed as well.

Each output was produced by running this tool on the input above it.

How it works

Three text replacements are applied in order: HTML comments are removed, whitespace between a > and the next < is removed, and every remaining run of two or more whitespace characters becomes one space.

Details and limits

  • The tool works on the text, without an HTML parser. Whitespace inside pre and textarea is collapsed like everywhere else.
  • In inline JavaScript, a line break followed by indentation is collapsed to a space. If a line ends with a // comment, the next statement is then on the same line and becomes part of the comment. Use /* */ comments or keep scripts in separate files.
  • A space between two inline elements (<b>a</b> <i>b</i>) is removed, which joins the words when the page is rendered.
  • Conditional comments are comments and are removed as well.

Questions

Is my data uploaded when I use HTML Minify?

No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.

What does HTML Minify do?

HTML Minify removes comments, removes whitespace between tags and collapses runs of spaces, to reduce the size of a page or template. It is a text-level minifier for simple markup, not a build-tool replacement.

How does HTML Minify work?

Three text replacements are applied in order: HTML comments are removed, whitespace between a > and the next < is removed, and every remaining run of two or more whitespace characters becomes one space.

Are there any limits I should know about?

The tool works on the text, without an HTML parser. Whitespace inside pre and textarea is collapsed like everywhere else. In inline JavaScript, a line break followed by indentation is collapsed to a space. If a line ends with a // comment, the next statement is then on the same line and becomes part of the comment. Use /* */ comments or keep scripts in separate files.

Is there a size limit?

There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.

Does it work on phones, and is it free?

Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.