Skip to content
ToolZone

HTML Minifier

Strip unnecessary whitespace, comments, and line breaks from HTML source code, reducing file size for faster page loads without changing the output.

Runs in your browser. Nothing you enter or upload leaves your device.

Input
Minified output…

Removes comments and collapses whitespace; <pre>, <textarea>, <script> and <style> are kept as written.

Keyboard shortcuts

Run the main action
⌘ / Ctrl + Enter
Copy the result
⌘ / Ctrl + Shift + Enter
Download the result
⌘ / Ctrl + S
Paste a file or image into file tools
⌘ / Ctrl + V
Search all tools
⌘ / Ctrl + K
Show these shortcuts
?

You can also drop files anywhere on the page.

About the HTML Minifier

The HTML Minifier shrinks HTML by stripping comments and squeezing out whitespace while leaving pre, textarea, script and style blocks untouched. Paste markup or open an .html file, compare the original, minified and gzipped sizes, and copy or download the result.

How it works

First, <pre>, <textarea>, <script> and <style> blocks are set aside untouched, because whitespace inside them matters. Then all <!-- ... --> comments are removed and every run of spaces, tabs and line breaks is collapsed to a single space.

Whitespace next to block-level tags such as <div>, <p>, <li> and <table> is removed entirely, since browsers never render it. Between inline elements like <b> and <i>, a single space is kept so words don't run together. Finally the protected blocks are put back exactly as they were, and the savings line shows the character difference.

How to use

  1. 1

    Paste your HTML into the input box, or click Open file.

  2. 2

    Review the minified result and the size cards.

  3. 3

    Click Copy or Download to use the minified HTML.

Worked examples

Indented list

A formatted unordered list.

Input
<ul> <li>One</li> <li>Two</li> </ul>
Result
<ul><li>One</li><li>Two</li></ul> (Saved 7 bytes, 18%)

Space between inline tags is kept

Bold and italic words separated by a space.

Input
<p>Some <b>bold</b> <i>text</i></p>
Result
<p>Some <b>bold</b> <i>text</i></p>

There is nothing to remove here: the single space between the inline elements is needed, so the words still render as "bold text".

Limitations
Inline <script> and <style> contents are not minified, only preserved. It is a pattern-based pass, not a full HTML parser, so a > character inside an attribute value can confuse it. Attributes, quotes, and optional tags are not shortened, and conditional comments are removed along with ordinary ones.
Assumptions
The HTML is reasonably well formed, with matching closing tags for <pre>, <textarea>, <script> and <style>.
Privacy
Minification happens in your browser and your HTML is not uploaded.

Frequently asked questions

Does minifying HTML change how the page looks?+

It shouldn't. Whitespace is only removed where browsers ignore it, spaces between inline elements are kept, and <pre> and <textarea> content is preserved. Checking the result in a browser is still good practice.

Should I minify HTML during development?+

No. Keep readable HTML while developing and minify as part of a production build or right before deployment.

Is the "bytes saved" figure exact?+

It is the difference in character count. For plain ASCII HTML that equals bytes; multi-byte characters like emoji make the real byte saving slightly different.

Will it break inline JavaScript?+

No. Inline <script> blocks are kept exactly as written, so // comments and line breaks inside them are safe.

Related tools