HTML Minifier – Compress HTML Online
Paste your HTML and instantly shrink it by removing comments, whitespace, and optional characters. The result is a compact, single-line (or minimal-line) document that's semantically identical to the original, so it renders the same way. Perfect for reducing page weight and speeding up delivery. Everything runs locally in your browser — no signup, no uploads.
Configure & input
Paste HTML and pick optionsCtrl + Enter (or Cmd + Enter) inside the input to minify instantly. Content inside <pre>, <textarea>, <script> and <style> is preserved exactly as written.
Minified output
Ready when you areYour minified HTML will appear here. Paste some markup and click Minify HTML.
What does an HTML minifier do?
An HTML minifier removes comments, whitespace between tags, optional closing tags, and redundant attribute syntax from an HTML document to reduce file size. HTML parsers ignore these characters, so minification doesn't change how the page renders — the elements, attributes, text content, and structure stay exactly the same.
What it does change is how much bandwidth it takes to transmit the page and how quickly it loads. Minified HTML is typically 10–25% smaller than the original, and on pages with heavy indentation and comments, the savings can be much higher.
This tool uses a character-by-character tokenizer that understands HTML structure. It correctly handles the doctype, elements, attributes, comments, CDATA sections, and protected content blocks (pre, textarea, script, style). Whitespace inside those blocks is preserved because removing it would change how the page renders or how the code executes.
Everything runs locally in your browser. The HTML you paste never leaves your device — no signup, no usage limit, and nothing to install. Paste, click, done.
How to minify HTML online
- Paste your HTML into the input box. It can be one line or thousands of lines — the tool handles both.
- Pick your options. Remove comments, collapse whitespace, remove optional closing tags, and collapse boolean attributes.
- Click Minify HTML. The tool rewrites your HTML without whitespace, producing a compact string.
- Review the result. The output panel shows the minified HTML with syntax highlighting, plus byte-size stats and the percentage saved.
- Copy or download. Copy the minified HTML to your clipboard or download it as a
.htmlfile.
Why minify HTML?
Smaller payloads
Whitespace and comments can make up 20–40% of a typical HTML document. Removing them shrinks the file and speeds up page loads.
Lower bandwidth
Smaller files mean fewer bytes over the wire — critical for mobile users, low-bandwidth regions, and high-traffic sites.
Same rendering
HTML parsers ignore whitespace between block elements. Minified HTML renders identically to the original — same layout, same behaviour.
Script and style safe
Content inside script and style tags is preserved exactly as written. Whitespace, comments, and special characters stay untouched.
Size comparison
See the exact byte size of the input and output side by side, along with the percentage reduction.
Works offline
Once the page loads, you can minify HTML without an internet connection. Bookmark it for offline work.
What gets removed during HTML minification?
| What | Before | After |
|---|---|---|
| Indentation | Newlines and spaces between elements | Removed (elements packed together) |
| Comments | <!-- comment --> | Removed when the option is enabled (IE conditional comments preserved by default) |
| Blank lines | Multiple blank lines | Collapsed to nothing |
| Trailing whitespace | Spaces at line ends | Removed |
| Optional closing tags | </p>, </li>, </td> | Removed when the option is enabled (browser infers them) |
| Boolean attributes | disabled="disabled" | disabled when the option is enabled |
| Whitespace in pre/textarea | <pre> text </pre> | Preserved — never touched |
| Script and style content | JS/CSS inside <script>/<style> | Preserved — never touched |
| Text content | <h1> Hello </h1> | Trimmed around the edges but internal spacing kept |
What is not changed: element names, attribute names, attribute values, CDATA contents, entity references, the doctype declaration, and processing instructions. The tool is conservative — it only removes whitespace that has no semantic meaning and comments (which are optional by design).
When to minify HTML (and when not to)
Good use cases for minification
- Production deployments: Shipping HTML over the wire to end users — every byte counts.
- Static site generators: Minify the final HTML output as part of your build pipeline.
- Email templates: HTML emails have strict size limits in some clients.
- Embedded content: HTML inside a widget or iframe benefits from compactness.
When to keep HTML readable
- During development: Readable HTML is much easier to work with. Minify at build time, not while you're editing.
- Hand-edited templates: If humans edit it, indentation helps.
- Debugging: Prettified HTML is easier to inspect in DevTools. Use browser source maps or keep a beautified copy.
Best practice: keep your source HTML beautified, and produce a minified version as part of your build or deployment pipeline. That way you never lose the readable original.
Frequently asked questions
<!--[if IE]>) are preserved by default because they affect rendering in older browsers. You can optionally remove them too.</p>, </li>, </td>). When the 'Remove optional tags' option is enabled, the minifier removes them, producing a smaller file that still renders identically.