Skip to main content

    HTML Minifier

    Minify HTML online. Strip comments, whitespace, and reduce file size for faster page loads.

    Free to use. Runs in your browser.

    Paste HTML and click Minify to remove whitespace, comments, and redundant attributes. Reduces page weight and improves Core Web Vitals.

    Input HTML

    Minified Output

    Why Minify HTML?

    HTML minification removes whitespace, comments, and optional tags that browsers don't need. A typical HTML page can shrink by 15-30% after minification. That's bytes that don't travel over the network, don't get parsed, and don't slow down your page load.

    Is it the biggest performance win? No, that's images, JavaScript, and CSS. But HTML minification is free performance. It costs nothing to implement, breaks nothing, and compounds with every page view. For a site with millions of visits, a 20% reduction in HTML size saves real bandwidth and money.

    Paste your HTML, get a minified version. The tool strips comments, collapses whitespace, and removes unnecessary attributes while preserving the document's functionality. Your HTML will render identically, just smaller.

    What Minification Removes

    ElementBeforeAfterSavings
    Whitespace <p> Hello </p><p>Hello</p>Usually 15-25% of file size
    Comments<!-- Navigation -->(removed)Varies, can be significant
    Empty attributesclass=""(removed)Small per occurrence
    NewlinesMultiple line breaksCollapsed to single space5-10% typical
    Optional end tags</li>, </p>(can be removed)Small but adds up in lists

    What this means for you: Minification is safe and reversible. If you need to debug, use the HTML Beautifier to re-format. Most build tools (Vite, webpack) can minify HTML automatically during production builds.

    Performance Optimisation Beyond Minification

    Enable Gzip/Brotli compression

    Server-side compression reduces HTML by 60-80%. Minification + Brotli together can reduce a 100KB page to under 10KB over the wire. Most CDNs and web servers support this with one config line.

    Inline critical CSS

    Put above-the-fold CSS directly in <style> tags to avoid render-blocking requests. The page renders instantly while the full stylesheet loads asynchronously. This is the #1 LCP optimisation.

    Defer non-critical scripts

    Add defer or async to <script> tags that aren't needed for initial render. Analytics, chat widgets, and social media embeds can all load after the page is interactive.

    Remove unused code

    Unused CSS and JavaScript are a bigger problem than unminified HTML. A single unused 50KB JS bundle dwarfs any HTML whitespace savings. Audit with Chrome DevTools Coverage tab.

    Typical HTML Page Sizes

    Page TypeRaw HTMLMinifiedMinified + Gzip
    Simple landing page15 KB11 KB3 KB
    Blog article30 KB22 KB7 KB
    E-commerce product page80 KB55 KB15 KB
    Dashboard (heavy tables)200 KB140 KB30 KB
    Average web page50 KB35 KB (30%)10 KB (80%)

    HTML is rarely the performance bottleneck, images and JavaScript are far larger. But minification is free savings with zero risk, and it's standard practice in every production build pipeline.

    Related Tools

    How to use this tool

    1

    Paste your HTML into the input area

    2

    Click Minify HTML to compress

    3

    Copy the result or download as a .min.html file

    Common uses

    • Reducing HTML file size for production deployment
    • Stripping comments from HTML before going live
    • Preparing HTML email templates for sending
    • Optimising static HTML pages for faster load times

    Share this tool

    Frequently Asked Questions

    What does HTML minification do?
    It removes comments, collapses whitespace, eliminates unnecessary line breaks, and strips optional tags. The result is the smallest valid HTML that renders identically to the original. A typical page shrinks 15-30%.
    Will minification break my page?
    No. Minification only removes whitespace and comments that browsers ignore anyway. Your tags, attributes, content, and functionality stay exactly the same. The page renders pixel-for-pixel identically.
    Is my HTML sent to a server?
    No. Everything runs in your browser using JavaScript regex operations. Nothing is uploaded, stored, or transmitted. Safe for production HTML containing sensitive data.
    Should I minify HTML for production?
    Yes, it's free performance. Minified HTML loads faster, parses quicker, and uses less bandwidth. Combined with Gzip/Brotli compression, a 100KB page can shrink to under 10KB over the wire.
    What's the difference between minification and compression?
    Minification removes unnecessary characters from the source code itself. Compression (Gzip, Brotli) encodes the file more efficiently for transfer. They're complementary, minify first, then compress. Together they reduce size by 70-90%.
    Does minification remove my CSS and JavaScript?
    No. Inline styles, embedded CSS, and JavaScript within the HTML are preserved. Only HTML comments and whitespace between tags are removed. For CSS and JS minification, use dedicated tools.
    Can I undo minification?
    Not exactly, comments are permanently removed. But you can re-format the structure using an HTML beautifier to restore readable indentation. That's why you should always keep your source files unminified and only minify for production.
    How much space will I save?
    Typically 15-30% depending on how much whitespace and comments your HTML contains. Heavily commented HTML with generous indentation saves more. Already-compact HTML saves less. The tool shows exact before/after sizes.
    Should I minify HTML or just rely on Gzip?
    Both. Gzip compresses what's there, but it still has to process every byte. Fewer bytes in = fewer bytes to compress = smaller Gzip output. Minification before compression gives the best result.
    Does Google care about minified HTML?
    Google doesn't directly rank minified vs unminified HTML. But minification improves page load speed, which is a ranking factor via Core Web Vitals. Faster pages also get better user engagement, which indirectly helps rankings.
    What about whitespace in pre tags?
    This tool collapses all whitespace uniformly. If your HTML contains <pre> or <code> blocks where whitespace matters, review those sections after minifying. Most production build tools have options to preserve whitespace in specific tags.
    Can I minify HTML automatically in my build?
    Yes. Vite uses html-minifier-terser by default in production builds. Webpack has HtmlWebpackPlugin with minify options. Most modern build tools handle this automatically, this online tool is for quick one-off jobs.

    Results are for general informational purposes only and should be checked before use. They are not professional advice. See our Disclaimer and Terms of Service.