ModernCalcs

HTML Minifier

Input: 360 charsOutput: 274 chars24% savings

HTML Minifier: Compact Documents for Faster Page Loads

HTML whitespace is for human readability — browsers ignore it during parsing. Minifying HTML removes comments, collapses inter-tag whitespace, and tightens attribute syntax to reduce document size and improve Time to First Byte without changing how the page renders.

Formula
html.replace(/<!--(?!\[if)[\s\S]*?-->/g, "") // remove comments .replace(/\s+/g, " ") // collapse whitespace .replace(/> </g, "><") // remove spaces between tags

IE conditional comments (<!--[if ... -->) are preserved. Whitespace inside <pre> or <textarea> may be affected — review the output before deploying if those elements are present.

Impact on Inline Elements

For block-level elements (div, section, p), whitespace between tags has no visual effect — browsers discard it. For inline elements like span or img placed side-by-side, that whitespace creates a small visual gap. If your layout relies on inline-block elements with no gap between them, verify the minified output renders correctly.

HTML Comments Removed

HTML comments () are removed entirely. They contribute to document size without affecting the rendered page. Internet Explorer conditional comments (.Paste the HTML email template

  • 2.Review the output for any inline-element gap issues
  • 3.Copy the minified HTML
  • 4.Paste into your email sending tool or embedded template string
  • What Gets Removed

    • HTML comments: (not IE conditional)
    • Whitespace between tags: collapsed to nothing
    • Optional spaces around attribute = assignment
    • Leading and trailing whitespace from the document

    Good Use Cases

    • Minifying HTML email templates for email service providers
    • Compacting static HTML files in CDN deployments
    • Reducing embedded HTML strings in JavaScript template literals
    • Checking byte savings before wiring up a server-side minifier

    Frequently Asked Questions

    What does HTML minification remove?

    HTML comments (except Internet Explorer conditional comments starting with developer tools