Skip to content

HTML Minifier

Strip comments, collapse whitespace, and shrink your HTML for faster page loads

0 characters

Reduce HTML File Size for Faster Page Delivery

HTML files carry significant formatting overhead — indentation, comments, optional closing tags, and default attribute values that browsers ignore. In template-generated pages with deep nesting, this overhead can account for 20–30% of the document size. Minification strips it away, producing a smaller file that downloads and parses faster without changing what the browser renders.

Safe Whitespace Handling

The minifier collapses consecutive whitespace characters (spaces, tabs, newlines) into a single space and removes whitespace between block-level tags where it has no visual effect. It is careful with elements where whitespace matters: content inside pre, code, textarea, script, and style tags is left completely untouched, and a single space is preserved between inline elements to maintain word separation.

Comment Removal

Standard HTML comments are removed entirely. Conditional comments used by older versions of Internet Explorer are detected and preserved, since they contain functional markup. If your build process uses comments as section markers, minify after the build step so those markers have already served their purpose.

Attribute Cleanup

Certain HTML attributes have default values that browsers apply automatically: type="text/javascript" on script tags, type="text/css" on style tags, and method="get" on forms. The minifier can remove these redundant attributes safely. Attribute values that don't contain special characters can also have their quotes removed, though this tool keeps quotes for maximum compatibility.

Combining with Gzip

Most web servers compress HTML with gzip or Brotli before sending it. Gzip is very good at compressing repeated whitespace, so the additional savings from minification after gzip are modest — typically 3–8%. The real benefit is reducing the raw document size that the browser must parse, which is especially noticeable on large pages with thousands of DOM nodes.

Privacy

All processing runs in your browser. No HTML is sent to any server, making this safe for internal applications, admin panels, and client projects.

$ faq

What does HTML minification remove?
It strips HTML comments, collapses runs of whitespace into single spaces, removes whitespace between tags where safe, and drops optional closing tags and default attribute values like type="text/javascript" on script tags. The rendered page looks identical.
Can minification break my page?
In rare cases, removing whitespace can affect inline elements where spacing between words matters (like spans inside text). The minifier is conservative and preserves a single space between inline elements. Pre-formatted content inside <pre>, <code>, <textarea>, and <script> tags is left untouched.
Does it minify inline CSS and JavaScript too?
No. This tool minifies only the HTML markup. Inline <style> and <script> content is preserved as-is. Use the dedicated CSS Minifier and JavaScript Minifier tools on Txtory for those.
How much smaller does HTML get?
Typical savings are 10–25% depending on how much whitespace and how many comments the original contains. Template-generated HTML with deep indentation can see 30% or more reduction.
Are conditional comments preserved?
Yes. Internet Explorer conditional comments () are preserved because they are functional, not decorative. Standard HTML comments are removed.
Should I minify HTML in production?
It depends. For static sites and landing pages, minification reduces transfer size. For server-rendered pages with gzip enabled, the benefit is smaller since gzip already compresses whitespace well. It never hurts, but the gains may be marginal compared to CSS and JavaScript minification.
Is my HTML sent to a server?
No. All processing runs in client-side JavaScript. Nothing is uploaded or stored.