Free Online HTML Minifier
Strip whitespace, comments, and redundant attributes from HTML
Try these next
Why use HTML Minifier
- Shows exact byte savings and compression percentage so you know the impact before committing the minified output.
- Handles HTML5 syntax including SVG, MathML, and Web Component templates without corruption.
- Leaves inline CSS and JavaScript intact -- it strips only HTML-level whitespace and comments.
- No build-tool configuration needed. Paste, copy, deploy.
How it works
The minifier processes HTML in a single pass through a series of transformations. First, HTML comments (<!-- ... -->) are removed using a regex that matches the comment delimiters and everything between them, with an exception for conditional comments used by older IE versions. Next, contiguous whitespace characters (spaces, tabs, newlines) between tags are collapsed to a single space or removed entirely when they appear between block-level elements where whitespace is not rendered. Boolean attributes like checked="checked" are shortened to just the attribute name. Optional closing tags (</li>, </p>, </td>) that HTML5 permits omitting are stripped when safe to do so. Default attribute values such as type="text" on input elements are removed. The tool measures the input byte count before processing and the output byte count after, computing the percentage reduction as (1 - output/input) * 100.
About this tool
HTML is the first thing the browser downloads. Every unnecessary byte -- comments, indentation, redundant attributes -- delays First Contentful Paint. This tool strips all of it and shows you exactly how many bytes you saved. Boolean attributes collapse (checked="checked" becomes checked), optional closing tags are removed, and whitespace between block elements disappears. Inline script and style blocks are left intact for their own minifiers. The minifier handles modern HTML5 syntax including SVG, MathML, and Web Component templates. Gmail truncates emails over 102 KB, so email developers use this to shrink templates below that threshold. Static site generators like Hugo and Eleventy don't always minify HTML by default. This tool fills that gap without configuring a build plugin.
How to use HTML Minifier
- Paste your HTML. Drop your markup into the input area -- full pages, partials, or email templates.
- Read the savings. Original and minified byte counts appear alongside the compression percentage.
- Copy the result. Click Copy to grab the minified HTML for your deploy.
Use cases
- An email template is hitting Gmail's 102 KB clipping threshold. Paste it in, check the savings, and confirm it's under the limit before sending.
- You're deploying a static landing page and want to shave bytes without configuring a build tool. Paste the HTML, copy the minified version.
Frequently Asked Questions
HTML minification is the process of removing unnecessary characters from HTML code without changing its functionality. This includes whitespace, line breaks, indentation, comments, and redundant attributes. The result is a smaller file that browsers render identically to the original, but downloads faster.
Typical HTML minification reduces file size by 10–30%, depending on how the original code is formatted. Heavily indented and commented code sees the largest reductions. When combined with gzip or Brotli compression on your server, total savings can reach 70–90% of the original file size.
No. HTML minification only removes characters that browsers ignore during rendering. The visual appearance and functionality of your page remain identical. However, if your CSS relies on whitespace between inline elements, removing it may cause minor layout shifts -test your pages after minification.
Yes. Minifying HTML is a standard production optimization that reduces download times and bandwidth costs. Most build tools (Webpack, Vite, Next.js) can minify HTML automatically. This online tool is useful for quick one-off minification, email templates, and static HTML files not processed by a build system.
Minification removes unnecessary characters from the source code itself, producing a smaller but still valid HTML file. Compression (gzip, Brotli) is applied by the web server when sending files to browsers, using algorithms to reduce transfer size. Both techniques are complementary -minify first, then compress for maximum savings.
This tool focuses on HTML minification. Inline CSS within <style> tags and inline JavaScript within <script> tags are preserved but whitespace within them may be collapsed. For dedicated CSS and JavaScript minification, use the CSS Minifier and JavaScript Minifier tools.
Yes, minified HTML can be reformatted (prettified) using code formatters or browser developer tools. However, removed comments and some optional attributes cannot be recovered. Always keep your original source files and only minify copies for production deployment.
Indirectly, yes. Google considers page speed as a ranking factor, and smaller HTML files load faster. Improved Core Web Vitals (LCP, FCP) from faster loading can positively affect search rankings. Minification alone may not cause dramatic improvements, but it is part of a comprehensive performance optimization strategy.
In nearly all cases, no. HTML minification removes comments, extra whitespace between tags, and optional closing tags that browsers handle automatically. It does not alter attribute values, inline scripts, or inline styles. The only edge case to watch for is inline JavaScript that relies on newlines as statement terminators instead of semicolons -always test minified output in a browser before deploying to production.
For typical hand-written or CMS-generated HTML, expect a 5–20% reduction in raw byte size. Pages with lots of comments, indentation, or verbose template output can see reductions above 30%. The impact on load time is most noticeable on pages that are not already served with gzip or Brotli compression -once a server compresses output, the marginal gain from minification is smaller but still worthwhile.
Yes, both techniques are complementary. Gzip works by finding repeated byte sequences, and minified HTML actually compresses slightly better because duplicate whitespace patterns are already removed. More importantly, minified HTML reduces the decompressed payload the browser has to parse, which speeds up rendering even after decompression.
Related Tools
Discover more free utilities to enhance your productivity.
CSS Minifier
Compress CSS by stripping whitespace, comments, and shortening values
JavaScript Minifier
Strip whitespace and comments from JavaScript without changing behavior
Markdown to HTML Converter
Turn Markdown into clean, sanitized HTML with GFM support
JSON Formatter & Validator
Paste messy JSON, get clean indented output