WebToolsPlanet
developer Tools

HTML Minifier

Compress HTML by removing whitespace, comments, and redundant attributes — with size reduction stats.

Last updated: March 25, 2026

Client-Side Processing
Input Data Stays on Device
Instant Local Execution

Find this tool useful? Support the project to keep it free!

Buy me a coffee

What 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

1

Paste your HTML code into the input area on the left

2

Choose your minification level using the option toggles:

3

Toggle "Minify inline CSS/JS" to compress <style> and <script> content too

4

Click "Minify" — the size reduction statistics appear above the output

5

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:

Original HTML (418 bytes)
<!-- 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>
Minified HTML (201 bytes — 52% smaller)
<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?
Standard whitespace removal is completely safe — browsers ignore whitespace between block elements. Only whitespace inside <pre>, <textarea>, and inline elements matters. These are preserved by default. Boolean attribute collapsing (required="" → required) and optional tag removal are also safe for modern browsers per the HTML5 spec.
How much size reduction can I expect from HTML minification?
Typically 10–30% for well-formatted HTML with comments. The actual network saving is smaller because web servers apply gzip or Brotli compression, which already removes redundant patterns efficiently. The main benefit of HTML minification is faster parsing time, especially on mobile devices with limited CPU.
Is it safe to remove HTML comments?
Usually yes — HTML comments are for developers, not browsers. Exceptions: IE conditional comments (<!--[if IE]>), some server-side template markers, and comments used as JavaScript anchor points (<!--#include virtual="..."--> SSI). Inspect your comments before enabling this option.
What are optional closing tags?
The HTML5 spec allows certain closing tags to be omitted because browsers infer them: </li>, </dt>, </dd>, </p>, </td>, </th>, </tr>. Removing them is valid per spec and saves a few bytes per occurrence. It is not recommended if your CSS uses :not(:last-child) or similar selectors that rely on sibling relationships.
Should I minify HTML separately or let my build tool handle it?
For production projects, use your build tool (Vite, Next.js, Webpack) which minifies as part of the build pipeline automatically. This tool is ideal for: CMS templates (WordPress, Drupal), static HTML sites without a build step, HTML email templates, and quick one-off optimization before manual deployment.
Does minifying HTML affect SEO?
No — Googlebot parses minified HTML identically to formatted HTML. The HTML structure, content, headings, and links are what matter for SEO, not formatting. If anything, smaller HTML improves TTFB slightly, which is a minor Core Web Vitals signal.

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

Browser-native JavaScriptRegex-based HTML tokenizerTerser (inline JS)CSS minifier pipelineClient-side only