HTML Minifier
Paste your HTML to strip comments and needless whitespace while keeping <pre>, <textarea>, scripts and conditional comments safe. See the size before and after and copy or download the result.
How to use the HTML Minifier
- Paste your HTML into the input box, or press Upload .html (you can also drop a file onto the box).
- Pick your options. The defaults are safe for almost every page; turn on “Remove optional attribute quotes” for a few extra bytes.
- Press Minify HTML. The output also updates live while you type.
- Check the savings in the Original, Minified and Saved cards.
- Copy or Download the minified HTML and use it in production. Keep your readable original for editing.
What the HTML minifier changes (and what it never touches)
| Input | Output | Why it is safe |
|---|---|---|
<!-- nav --> | (removed) | Comments are never displayed. |
<div>⏎␣␣<p>Hi</p>⏎</div> | <div><p>Hi</p></div> | Whitespace between block elements does not render. |
<b>a</b>␣␣⏎<i>b</i> | <b>a</b>␣<i>b</i> | One space is kept between inline elements so words stay apart. |
class="a␣␣␣b" | class="a b" | Class lists are space-separated tokens. |
checked="checked" | checked | For boolean attributes only presence matters. |
<script type="text/javascript"> | <script> | JavaScript is the default script type in HTML5. |
<br /> | <br> | Void elements need no closing slash in HTML5 (SVG keeps its />). |
<pre>, <textarea> | (unchanged) | Whitespace is meaningful inside them. |
Worked example: how the savings are calculated
The saving is (original bytes − minified bytes) ÷ original bytes × 100, measured in UTF-8 bytes, which is what your server actually sends. If a template is 18,400 bytes and the minified version is 14,720 bytes, you save 3,680 bytes, which is 3,680 ÷ 18,400 = 20%.
Minification and compression work together. Gzip or Brotli shrink repeated text extremely well, so a 20% saving before compression often becomes a 5–10% saving after it. That is still worthwhile on pages served millions of times, and minified HTML is also parsed slightly faster.
Tips for minifying HTML safely
- Minify as part of your build or deploy step and keep the readable source in version control.
- If you rely on
white-space: prein CSS for an element other than<pre>, keep that content in a<pre>or turn off whitespace collapsing. - Inline scripts are minified lightly and conservatively. For bundles of JavaScript use a dedicated tool such as a JS minifier in your build.
- Template placeholders like
{{ name }}are left intact because they are ordinary text.
Frequently asked questions
What does an HTML minifier do?
It removes characters the browser does not need, such as comments, indentation and line breaks between tags, so the file is smaller and downloads faster. The page looks and behaves the same.
Is it safe to minify HTML?
Yes, when whitespace is handled carefully. This tool keeps a single space between inline elements and words, leaves <pre> and <textarea> content untouched and never rewrites the contents of strings in scripts. Always test the minified page once before deploying.
How much smaller will my HTML get?
Typically 10–25% for hand-written pages and more for heavily indented templates or pages with many comments. Combined with gzip or Brotli compression on your server, minified HTML saves a little more on top.
What are conditional comments?
Comments such as <!--[if lt IE 9]> … <![endif]--> that old versions of Internet Explorer read as code. They are kept by default so legacy fallbacks keep working; untick the option to remove them too.
Does it minify inline JavaScript and CSS?
Yes, lightly. It removes comments and extra whitespace in <style> blocks, style attributes and inline scripts. Line breaks in JavaScript are kept where they could matter for automatic semicolon insertion. For maximum compression of large scripts use a dedicated JS minifier.
When can attribute quotes be removed?
HTML allows unquoted attribute values when they contain no spaces or any of the characters " ' ` = < >. With the option enabled, quotes are removed only from such values, for example class=card instead of class="card".
Is my code uploaded anywhere?
No. The minifier runs entirely in your browser with JavaScript, so your HTML never leaves your computer.