All Tools

HTML Minifier, Shrink HTML and See Bytes Saved

Remove the whitespace and comments HTML does not need and see how many bytes you saved. Four options, and pre, textarea, script and style content is kept exactly. Nothing is uploaded.

Removes the line breaks and indentation between block elements.

Turns runs of spaces and line breaks in text into one space.

Drops comments, but keeps conditional comments.

Removes extra spaces inside tags and around attribute values.

0 characters, 0 bytes

0 characters, 0 bytes


About the HTML Minifier

The HTML Minifier removes the whitespace and comments that a browser does not need, so the same page takes fewer bytes. Paste HTML into HTML and the compact version appears next to it as you type, with a note that gives the bytes before and after and the percentage saved. Four switches let you decide what gets removed, and Download .html saves the result.

Your HTML never leaves your device. The minifier runs in the page, so nothing is uploaded, logged or stored, and it is gone when you close the tab. The minifying code is only downloaded the first time you type, so the page stays light until you use it.

How to use it

Steps

  1. Paste or type HTML into HTML.
  2. Leave the four options on, or turn off any you do not want.
  3. Read the note under the result, such as Saved 4 bytes (16.7%): 24 bytes to 20 bytes.
  4. Press Copy or Download .html.

The four options

  • Remove whitespace around block tags removes the line breaks and indentation between block elements such as div, ul and section, where a browser shows no gap anyway.
  • Collapse whitespace in text turns each run of spaces, tabs and line breaks inside text into a single space.
  • Remove comments drops ordinary comments. Conditional comments, such as those older Internet Explorer pages use, are always kept.
  • Trim whitespace inside tags removes extra spaces inside tags and around attribute values, so <a href = "x" > becomes <a href="x">.

Each option changes only its own kind of whitespace, so you can turn one off without affecting the others.

What is never touched

Content where whitespace matters is copied exactly: pre, textarea, script, style and title. A single space between two inline elements is kept, because <b>a</b> <i>b</i> and <b>a</b><i>b</i> look different on screen. Non-breaking spaces are kept as well. Nothing is renamed, reordered or rewritten, and attribute values are not changed apart from the spaces around them.

How the saving is measured

The note counts UTF-8 bytes, which is what a server sends, so an accented letter counts as 2 bytes and an emoji as 4. The percentage is

saved=bytes in−bytes outbytes in×100\text{saved} = \frac{\text{bytes in} - \text{bytes out}}{\text{bytes in}} \times 100

For example, <div>\n <p>Hi</p>\n</div> is 24 bytes and <div><p>Hi</p></div> is 20 bytes, so the saving is 24−2024≈16.7%\frac{24 - 20}{24} \approx 16.7\%. Markup that is already compact shows No bytes saved. Servers usually also apply gzip or Brotli, which saves far more, but minifying first still helps.

Safe to repeat

Minifying the result again changes nothing, and the test suite checks that removing all whitespace from the input and from the output gives the same string, so no tag or word is lost. To read minified markup again, use the HTML Formatter, and to shrink a stylesheet use the CSS Minifier.

Frequently asked questions

Is my HTML uploaded to be minified?

No. The minifier runs in your browser, so the markup is not uploaded, logged or stored. Closing the tab clears it. The minifying code is downloaded the first time you type, and after that no request is made with your HTML.

Will minifying break my page?

It only removes or shortens whitespace and comments. Content in pre, textarea, script, style and title is copied exactly, and a single space between inline elements is kept, so the rendered page should look the same. Check the result before deploying.

Are conditional comments removed?

No. Remove comments drops ordinary comments only. Conditional comments, the ones starting with if or ending with endif, are always kept because some old browsers rely on them.

How is the saving calculated?

It compares the UTF-8 byte size of the input and the output, which is what a server actually sends. Accented letters take 2 bytes and emoji 4, so the figure can differ from a character count. If nothing could be removed, the note says no bytes were saved.

Does it minify the CSS and JavaScript inside my HTML?

No. Style and script content is copied exactly. Use the CSS Minifier for stylesheets, and a dedicated JavaScript minifier in your build tool for scripts.

Other related tools