HTML Minifier

Strip comments and collapse whitespace while preserving pre/code/script

Input

Minified Output

Minified HTML will appear here

About

This tool minifies HTML documents by removing comments and collapsing whitespace between tags, while preserving the content of <pre>, <textarea>, <script> and <style> elements. Use it to shrink static HTML before deploy or to trim pasted markup. Minification runs entirely in your browser; nothing is uploaded.

    Examples

    Minify a page with a code block

    Input
    <div>
      <!-- a comment -->
      <h1>Hello</h1>
      <pre>
        code
      </pre>
    </div>
    Output
    <div><h1>Hello</h1><pre>
        code
      </pre></div>

    Comments are stripped, inter-tag whitespace is collapsed, and the indentation inside <pre> is preserved exactly.

    Strip redundant attribute quoting

    Input
    <a href="/x" target=_blank rel="noopener noreferrer">Link</a>
    Output
    <a href=/x target=_blank rel="noopener noreferrer">Link</a>

    Quotation marks are removed from attribute values that don't contain whitespace or special characters, shaving bytes without changing browser behavior.

    About this tool

    The HTML Minifier shrinks HTML source by stripping comments, collapsing inter-tag whitespace, and removing redundant quoting on attribute values, while preserving the byte content of <pre>, <code>, <textarea>, <script>, <style> and CDATA so code samples, inline scripts and stylesheets survive intact.

    Useful when you need to ship smaller HTML — generated pages, email bodies, static-site output, or any markup that grew noisy in development and is now ready for production. Minification runs entirely in your browser; the input is never uploaded or stored.

    How to use

    1. Paste your HTML

      Drop the markup into the input editor, or load a sample to see a quick before/after.

    2. Choose options

      Toggle comment removal, whitespace collapse, and attribute-quote cleanup. Whitespace inside <pre>, <code>, <textarea>, <script> and <style> is always preserved.

    3. Copy the result

      Click Copy to copy the minified HTML, or download it for use in production.

    Use cases

    Shrinking production HTML

    Cut kilobytes from generated HTML before serving it, especially on content-heavy pages where the savings compound across impressions.

    Sanitizing pastes before commit

    Strip developer comments and excess whitespace from hand-edited templates so committed markup stays clean in version control.

    Preparing email HTML

    Reduce file size of HTML email bodies to avoid clipping by client-side size limits and improve mobile rendering speed.

    Common mistakes

    Mistake:Trusting minified output to be byte-identical except for whitespace.

    Fix:Safe minifiers are conservative — they may collapse quotes, drop optional slashes, or remove boolean attributes. Always sanity-check the result before deploying.

    Mistake:Applying minification to a debug build.

    Fix:Minify only the production build. Source maps and readable markup matter when investigating real bugs, so keep the unminified version for development.

    Mistake:Assuming whitespace inside arbitrary tags is preserved.

    Fix:Only <pre>, <code>, <textarea>, <script>, <style> and CDATA are protected. Whitespace inside <p> or <div> is collapsed by design — that's the point.

    Frequently asked questions

    References & standards