Minify HTML: free online HTML minifier

Paste a page or a snippet and get a smaller version as you type, with the exact byte savings. Preformatted text, scripts and styles are left exactly as they are.

Runs in your browser. Nothing you enter is uploaded.

Content of <pre>, <textarea>, <script> and <style> is never changed, and IE conditional comments are kept.

How to use the HTML minifier

  1. Paste your HTML into the HTML box, or click Example to load a sample page.
  2. The minified markup appears on the right as you type, with the size before and after.
  3. Untick Remove comments or Collapse whitespace if you want to keep either of them.
  4. Click Copy, or Download .html to save the result as a file.

What does minifying HTML remove?

It removes comments, the indentation and line breaks between block elements such as <div>, <p> and <li>, and runs of spaces inside text. Inside tags it collapses the space between attributes, so <a href="x" class="y" > becomes <a href="x" class="y">. Attribute values themselves are never changed. The example page shrinks from 494 B to 397 B, about 20 percent.

Some whitespace has to stay. Between inline elements a single space is visible on the page: in <b>bold</b> <i>italic</i> the space keeps the two words apart, so the minifier keeps exactly one. Text inside <pre> and <textarea> is shown exactly as written, and <script> and <style> contain code, so all four are copied byte for byte.

Is minified HTML worth it?

For pages with a lot of indentation and comments the saving is noticeable, and every byte of the HTML document matters because the browser needs it before it can show anything. Web servers usually compress HTML with gzip or Brotli as well. Compression and minifying work together: compression cannot remove comments, and a minified page still compresses well.

Keep your readable source for editing and publish the minified copy. Build tools and static site generators can minify HTML automatically on every build; this page is handy for one-off files, email templates or checking what a minifier will change.

Frequently asked questions

Will minifying HTML break my page?

This minifier is deliberately conservative. It keeps one space between inline elements, never touches attribute values, and leaves <pre>, <textarea>, <script> and <style> content unchanged. It does not remove optional closing tags or attribute quotes. As with any build step, check the page once after minifying.

Does it minify inline CSS and JavaScript?

No. The contents of <style> and <script> blocks are copied exactly as written, so nothing in your code can break. To shrink a stylesheet, run it through a CSS minifier separately and paste the result back in.

Why are some comments kept?

Conditional comments such as <!--[if IE]> … <![endif]--> contain real markup that old versions of Internet Explorer read, so removing them could change how a page behaves. They are always kept. Every other comment is removed unless you untick Remove comments.

What does Collapse whitespace do?

It turns runs of spaces, tabs and line breaks into a single space, drops whitespace next to block elements where it never shows, and tidies the spacing inside tags. With it unticked, the tool only removes comments and leaves everything else byte for byte.

Is my HTML uploaded anywhere?

No. Minifying happens entirely in your browser, so your markup never leaves your device. Your last input is remembered in your browser's local storage so it is still there when you come back.

Related tools