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 options
Tip: Press Ctrl + 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 are
Ready — paste HTML and click Minify.

Your 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

  1. Paste your HTML into the input box. It can be one line or thousands of lines — the tool handles both.
  2. Pick your options. Remove comments, collapse whitespace, remove optional closing tags, and collapse boolean attributes.
  3. Click Minify HTML. The tool rewrites your HTML without whitespace, producing a compact string.
  4. Review the result. The output panel shows the minified HTML with syntax highlighting, plus byte-size stats and the percentage saved.
  5. Copy or download. Copy the minified HTML to your clipboard or download it as a .html file.

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?

WhatBeforeAfter
IndentationNewlines and spaces between elementsRemoved (elements packed together)
Comments<!-- comment -->Removed when the option is enabled (IE conditional comments preserved by default)
Blank linesMultiple blank linesCollapsed to nothing
Trailing whitespaceSpaces at line endsRemoved
Optional closing tags</p>, </li>, </td>Removed when the option is enabled (browser infers them)
Boolean attributesdisabled="disabled"disabled when the option is enabled
Whitespace in pre/textarea<pre> text </pre>Preserved — never touched
Script and style contentJS/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

An HTML minifier removes comments, whitespace between tags, optional closing tags, and redundant attribute syntax from HTML documents to reduce file size. HTML parsers ignore these characters, so minification doesn't change how the page renders. The result is a smaller payload that downloads faster.
Yes, completely free. No signup, no watermark, no hidden charges. Minify as much HTML as you want, as many times as you want.
No. Minifying only removes whitespace between tags, comments, and other optional characters that HTML parsers ignore. The elements, attributes, text content, and structure of your HTML stay exactly the same, so the page renders identically in the browser.
Content inside pre, textarea, script and style tags is preserved exactly as written. The minifier does not touch whitespace or comments inside these elements because it would change how the page renders or how the code executes.
Yes. The tool handles HTML up to several megabytes easily. Very large files (over 10 MB) may take a moment to process depending on your device, but there's no hard limit.
Yes. When the 'Remove comments' option is enabled, IE conditional comments (like <!--[if IE]>) are preserved by default because they affect rendering in older browsers. You can optionally remove them too.
Yes, optionally. HTML allows certain closing tags to be omitted (like </p>, </li>, </td>). When the 'Remove optional tags' option is enabled, the minifier removes them, producing a smaller file that still renders identically.
No, this tool focuses on HTML structure. To minify inline CSS or JavaScript, use a dedicated CSS or JavaScript minifier first, then paste the result here to compress the surrounding HTML.
Absolutely. Everything runs in your browser. The HTML you paste never leaves your device — no server processing, no logging, no data storage. Close the tab and it's gone.
Yes. Use the Download .html button to save the minified HTML as a file. The file is created entirely in your browser using a Blob URL — no server round-trip.
Yes. Once the page loads, the HTML minifier works without an internet connection. All processing happens locally in your browser using JavaScript.
Minify compresses HTML by removing whitespace, comments, and optional characters to make the file as small as possible. Beautify (format) does the opposite — it adds indentation and line breaks to make HTML readable. Use minify for production, beautify for editing.