How to minify HTML
- Paste your HTML into the box.
- Leave Remove HTML comments checked to delete comments, or uncheck it to keep them. It is checked by default.
- Select Minify HTML. The result appears only after you press the button.
- Read the count under Result, then select Copy result.
For example, a five-line block with a <!-- Header --> comment, a div and two indented paragraphs becomes <div class="box"><p>Hello world</p><p>Second</p></div>. The tool reports 79 characters to 54, with 25 removed. The three spaces in Hello world become one.
What the minifier does
The tool applies four steps in this order:
- If the option is on, every
<!-- -->comment is deleted, including conditional comments. - Any whitespace between a closing
>and the next<is removed completely. - Every line break is deleted. It is not replaced with a space.
- Any run of two or more spaces or tabs becomes one space.
It does not remove quotes around attributes, drop optional closing tags, shorten boolean attributes or minify the CSS and JavaScript inside the page. For a stylesheet on its own, use the CSS Minifier.
Where the output can break your page
Because the rules do not know which tags care about whitespace, some markup comes out different. These are real results from the tool:
| You paste | You get | Effect |
|---|---|---|
| <p>Hello(new line)world</p> | <p>Helloworld</p> | Words on separate lines are joined |
| <b>Hello</b> <i>world</i> | <b>Hello</b><i>world</i> | Space between inline tags is lost |
| <pre>line 1(new line) line 2</pre> | <pre>line 1 line 2</pre> | Preformatted layout is flattened |
| <textarea>a(blank line)b</textarea> | <textarea>ab</textarea> | Default text loses its line breaks |
| <script>(new line)// note(new line)var a = 1;</script> | <script>// notevar a = 1;</script> | The code is now inside the comment |
| <a(new line)href="x"> | <ahref="x"> | The tag name and attribute merge |
Lines that start with indentation are safer. Hello, a line break, then an indented world comes out as Hello world, because the indent turns into a single space. Spaces inside a line, such as in Price: <strong>$5</strong> per month, are kept.
How to use it safely
- Minify static markup such as layout blocks, lists and tables, where each tag sits on its own indented line.
- Leave
<pre>,<textarea>and inline<script>blocks out, or move scripts into separate files. - In inline scripts, use
/* */comments and end each statement with a semicolon. - Uncheck comment removal if your page uses conditional comments or template markers inside comments.
- Open the minified page in a browser and compare it with the original before you publish.
Is minifying HTML worth it?
It helps most on large, deeply indented pages. The counter shows characters, which matches bytes for plain English text. Most servers also compress HTML with gzip or Brotli, and compression already handles repeated spaces well, so the real transfer saving is smaller than the counter shows. Minify and compress together. Page speed is only one small part of how search engines rank pages, so treat minifying as tidy housekeeping, not a ranking fix.
Minifying cannot be fully undone. The HTML Formatter can add indentation back, but deleted comments and joined words stay that way. Keep your original file.
Common Mistakes to Avoid
Minifying a page with inline scripts that use // comments
Solution:
Assuming the visible text will not change
Solution:
Minifying code samples inside pre tags
Solution:
Removing comments your build or template relies on
Solution:

