HTML Minifier
Compress HTML by removing whitespace, comments, and redundant attributes — with size reduction stats.
Last updated: March 25, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is HTML Minifier?
HTML minification removes every unnecessary character from an HTML document — whitespace between tags, newlines, HTML comments, redundant attribute quotation, and optional closing tags — without changing what the browser renders. A well-minified HTML file is typically 10–30% smaller than its formatted source. While this has less impact than CSS or JavaScript minification (HTML is usually gzip-compressed by web servers, which makes the benefit smaller), it still directly reduces Time to First Byte (TTFB) and initial parse time.
This tool uses a configurable minification pipeline, giving you control over which optimizations to apply: remove whitespace only (safest), also remove HTML comments, collapse boolean attributes (required → required), or remove optional closing tags (like </li> and </td>). Inline CSS within <style> tags and JavaScript within <script> tags can optionally be minified too, using the same rules as the dedicated CSS Minifier and JavaScript Minifier tools.
How to Use HTML Minifier
Paste your HTML code into the input area on the left
Choose your minification level using the option toggles:
Toggle "Minify inline CSS/JS" to compress <style> and <script> content too
Click "Minify" — the size reduction statistics appear above the output
Copy the minified HTML or download it as an .html file
Common Use Cases
- Minifying HTML template files before deploying to a static web host or CDN
- Compressing HTML email templates to reduce email client rendering overhead
- Reducing HTML size for AMP (Accelerated Mobile Pages) which have strict size budgets
- Removing development comments from HTML before publishing a website or theme
- Optimizing HTML embedded in a mobile app's WebView to reduce initial load time
- Compressing server-side rendered HTML fragments before caching in Redis or Memcached
- Removing whitespace from SVG markup embedded inline in HTML for minor size savings
- Quick verification of how much a specific HTML file can be reduced before a full build setup
Example Input and Output
A formatted HTML nav component minified to remove whitespace and comments:
<!-- Navigation bar component -->
<nav class="nav-bar" role="navigation">
<ul class="nav-links">
<li class="nav-item">
<a href="/" class="nav-link active">Home</a>
</li>
<li class="nav-item">
<a href="/about" class="nav-link">About</a>
</li>
</ul>
</nav><nav class="nav-bar" role="navigation"><ul class="nav-links"><li class="nav-item"><a href="/" class="nav-link active">Home</a><li class="nav-item"><a href="/about" class="nav-link">About</a></ul></nav>Privacy First
All HTML minification runs in your browser. Your HTML source code (which may contain internal URLs, API keys in inline scripts, or business logic) is never transmitted to our servers.
Email Template Tip
For HTML emails, minify conservatively — only remove whitespace and comments. Do NOT remove optional closing tags in email HTML. Email clients like Outlook 2016 use a Word-based renderer that is not fully HTML5 spec-compliant and may break with missing tags.
Inline Content Warning
Minifying inline <script> blocks can break scripts that rely on specific whitespace formatting (rare) or contain embedded HTML comment syntax (/* */ or // style comments that contain </script>). If your inline scripts behave unexpectedly after minification, toggle off "Minify inline JS" first.
Frequently Asked Questions
Will HTML minification affect how my page looks or behaves?
How much size reduction can I expect from HTML minification?
Is it safe to remove HTML comments?
What are optional closing tags?
Should I minify HTML separately or let my build tool handle it?
Does minifying HTML affect SEO?
How This Tool Works
The minification pipeline processes the HTML string in passes. First, HTML comments are stripped using a regex that handles multi-line comments. Then the input is tokenized into text nodes, tag nodes, and attribute nodes. Whitespace between block-level elements is collapsed to a single space or removed. Attribute values are normalized (unnecessary quotes removed, boolean attributes collapsed). Optionally, </li>, </td>, </tr> and other optional end tags are removed. Inline <style> content is processed by the CSS minifier pipeline; inline <script> content is processed by the Terser JavaScript minifier.
Technical Stack