Skip to main content

HTML Minifier

Minify HTML by collapsing whitespace, removing comments and optionally minifying inline CSS and JavaScript. Content inside <pre>, <textarea>, <script> and <style> is never mangled, and conditional comments survive.

Input

Drop a file or browse
One file · text
Or

Settings

Never applied inside <pre> or <textarea>.

Output

Minified HTML
 
Was this helpful?

Guides

Paste a page and get it back with the whitespace collapsed, the comments gone, and — if you want — the inline <style> and <script> blocks minified too. Useful for email templates, static pages, embedded widgets, and any HTML you are about to paste into a CMS field that charges you by the byte.

How to use it

  1. Paste your HTML into the input box, or upload an .html file.
  2. Toggle the settings:
    • Collapse whitespace — the main saving.
    • Remove HTML comments — conditional comments are always kept.
    • Remove quotes around attributes when possibleclass="card" becomes class=card where that is safe.
    • Minify CSS in <style> blocks and style="…" attributes.
    • Minify JavaScript in <script> blocks.
  3. Copy the result or download it as an .html file.

What it will never mangle

Minifying HTML naively breaks pages, so the tool is built around a set of guarantees:

  • <pre> and <textarea> are untouched, byte for byte. Whitespace inside them is rendered content — collapsing it visibly changes the page. Your ASCII art and your code samples come out exactly as they went in.
  • <script> and <style> bodies are never whitespace-collapsed by the HTML pass. They are either handed to a proper JavaScript or CSS minifier — one that understands string literals, regular expressions and comment-like strings — or passed through untouched. A <script type="application/json"> or text/x-template is always left alone.
  • Conditional comments survive. <!--[if lt IE 9]> … <![endif]--> is markup, not commentary, and removing it would delete a real script tag.
  • Inline spacing is preserved. <span>a</span> <span>b</span> renders with a space between the words and <span>a</span><span>b</span> does not. The tool knows which elements are inline, so it only drops whitespace between block-level elements where it cannot be seen.
  • Self-closing slashes are only stripped from void elements. <br/> becomes <br>, but SVG's <path/> keeps its slash — removing it would leave the element unclosed and swallow the rest of your graphic.

When is it unsafe to unquote an attribute?

When the value is empty, contains whitespace, quotes, backticks, =, < or > — or ends in a /. That last one bites people: href=/a/ immediately before the > gets parsed as a self-closing slash, truncating the URL. The tool checks all of these and leaves the quotes on when in doubt.

How much smaller does HTML get?

Usually 10–25% on hand-written markup, more on deeply-indented template output. Enabling the CSS and JS options helps a lot on pages with big inline blocks. As always, gzip/brotli on the server does more than minification — use both.

Does it strip entities like &amp;?

No. Rewriting &amp; to a raw & requires knowing whether the result would still be valid in that position; getting it wrong produces broken markup to save a handful of bytes. Entities are left exactly as you wrote them.

Will it fix broken HTML?

No — it is a minifier, not a sanitiser or a formatter. Unclosed tags stay unclosed. Run the output through a validator if you are unsure about the source.

Is my HTML uploaded anywhere?

No. The minifier runs entirely in your browser. Your markup is never sent to a server, never logged and never stored, and uploading a file reads it locally in the page. It works offline.

htmlminifiercompressformatterwebperformance

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.