HTML Minifier

Minify HTML by removing comments, extra whitespace, and optional attributes

About This Tool

Paste HTML in the left pane and read the minified version on the right. The tool strips comments, collapses whitespace, removes optional closing tags, and drops attribute quotes where the spec allows it.

Use it on hand-written pages, email templates, or static fragments before they ship. Modern build tools (esbuild, swc, Vite) handle this for component files, but a one-off paste is faster than wiring up a config for a single email or landing page.

The output keeps semantic correctness — ID and class names, script and style content, conditional comments — untouched. A byte-count delta in the corner tells you how much smaller the result is.

The transformations applied: collapse runs of whitespace to a single space, remove HTML comments (except IE conditional comments), drop optional closing tags where the spec allows (li, p, tr, td, etc., have implicit close rules), remove quotes from attribute values that contain only safe characters, lowercase tag names, and remove the trailing slash from void elements. The end result is byte-equivalent to the original under any compliant browser parser, but smaller in transit.

Worked example. Input:

<!-- header --> <ul> <li>One</li> <li>Two</li> </ul>

Output:

<ul><li>One<li>Two</ul>

From 56 bytes down to 27 bytes, a 51% reduction. The closing </li> tags are implicit before the next <li> or </ul> per the HTML spec, so the parser builds the same DOM either way. Comments are gone. Inter-tag whitespace is gone. The page renders identically; the wire transfer is smaller.

Where the minifier deliberately stops short. It does not touch the contents of <script> or <style> tags — those need a JS or CSS minifier respectively, and combining them into one tool produces worse output than running each through its specialist. It does not rewrite inline event handlers (onclick, etc.) because the savings are marginal and the failure mode is silent breakage. It does not collapse whitespace inside <pre>, <textarea>, or <code> tags, where whitespace is significant.

The contrarian take: for component-driven sites built with React/Vue/Svelte, the build pipeline (esbuild, Vite, Turbopack) minifies HTML output as a final step, and you don't need this tool. Where it earns its keep is hand-written HTML — landing pages, transactional emails, static documentation, configuration snippets that ship as HTML strings. Those are the places where running a one-off paste through a minifier saves real bytes per request, and where wiring up a build step would be overkill. Email templates especially: every byte over the gmail clip threshold (102 KB) gets quietly truncated, so trim aggressively.

The about text and FAQ on this page were drafted with AI assistance and reviewed by a member of the Coherence Daddy team before publishing. See our Content Policy for editorial standards.

Frequently Asked Questions