What does HTML Minifier do?
Minify HTML in your browser. Removes comments, collapses whitespace without touching pre or textarea, minifies inline JS and CSS and shows the size saved.
- Price
- Free
- Account
- Not required
- Processing
- Entirely in your browser; your data and files are not uploaded
- Works on
- Any modern browser on desktop, tablet or phone
- Category
- Developer Tools
How to use the html minifier
- Paste HTML or open an .html file.
- Choose options. The defaults remove comments, collapse whitespace and minify inline scripts and styles.
- Turn on "Remove attribute quotes" only if you want the smallest output; it is applied only where the HTML spec allows it.
- Select Minify HTML. The original size, output size and percentage saved appear above the output.
- Copy the result or download it as an .html file, then test the page before deploying it.
Worked example
A small product card
The 140-byte input <div class="card"> with an HTML comment, an indented <h2> Blue mug </h2> and a paragraph with extra spaces minifies to <div class="card"><h2>Blue mug</h2><p>Holds <strong>350 ml</strong> and is dishwasher safe.</p></div>, 101 bytes, a 27.9% saving. The spaces around <strong> are kept because they are visible on the page.
How it works
The HTML is split into tags, text, comments and raw text blocks by a small tokenizer that follows the HTML syntax rules for quoted attributes and raw text elements. Comments are removed except conditional comments and, optionally, <!--! licence comments. Runs of spaces, tabs and line breaks in text become one space, and whitespace next to block-level tags (such as div, p, li and table cells) is dropped because browsers do not render it. Text inside <pre> and <textarea> and all attribute values are copied unchanged. Inline scripts with no type or a JavaScript type are minified with Terser and <style> blocks with CSSO, both loaded in your browser on first use. If either fails, the original block is kept and a warning is shown.
Assumptions
- Whitespace next to block-level elements is treated as not rendered. If your CSS makes those elements inline or sets white-space: pre on them, check the output.
- Scripts with other types (for example text/template or text/x-handlebars) are left exactly as they are.
Frequently asked questions
Is my data uploaded?
No. This tool runs entirely in your browser. Your input is processed on your device and is not sent to our server or stored.
Can I minify templates (Handlebars, Jinja, EJS, PHP)?
Not reliably. A template is not HTML until it is rendered, and moving whitespace or quotes can change what the template produces. The tool warns when it finds {{ }}, {% %}, <% %> or PHP tags. Minify the rendered HTML instead.
Does it remove optional closing tags like </li> or </p>?
No. That saves a few bytes but can change how some pages are parsed, so this tool never removes tags.
Is minified HTML worth it if my server uses gzip or Brotli?
Compression already shrinks repeated whitespace well, so the gain is usually smaller after compression. Minifying still removes comments and reduces work for the browser, and the two work together.
Limitations
- Optional closing tags and redundant attributes (such as type="text/javascript") are not removed.
- Inline style and event handler attributes (style="...", onclick="...") are not minified.
- Server-side templates are not supported; the tool warns when it detects template syntax.
- Very large files (several MB) can take a few seconds on slower devices.