HTML Minifier
Shrink HTML by removing whitespace and comments.
Input HTML
325 bytes · 16 lines
Minified HTML
0 bytes
What is an HTML Minifier?
An HTML minifier shrinks an HTML document by removing characters that the browser does not need to render the page correctly — comments, redundant whitespace, empty attributes, optional closing tags. The output renders identically to the input but ships in a smaller payload, which makes the page load faster, uses less bandwidth, and ranks better under Core Web Vitals (because LCP improves proportionally to initial HTML size).
Typical savings depend on how verbose the source is. Hand-written HTML with standard indentation shrinks 20–30%. Templated HTML with comments, whitespace-only text nodes, and pretty-printed attributes can shrink 40–50%. Already-minified HTML from a modern framework (React server components, Svelte output) usually shrinks less than 10% because the framework has already removed most of the slack.
Our minifier is intentionally conservative. It strips HTML comments, collapses runs of whitespace, removes space around the = in attributes, and compresses between-tag whitespace — which together cover the great majority of real-world savings without risk of breaking the page. Crucially, it preserves the contents of <pre>, <code>, <textarea>,<script>, and <style> blocks untouched — whitespace inside those elements is meaningful and collapsing it would change how the page renders or executes.
When to minify. At build time or deploy time for static pages, blog templates, email templates, and landing pages. Most modern build tools (Next.js, Astro, Eleventy, Hugo) minify HTML output automatically; this tool is for one-off use when you're sending HTML to a system that does not — a legacy CMS, an email provider, a wrapper script. Gzip compression (standard on every HTTPS connection) applies on top of minification and compounds the savings.
What this minifier does not do. It does not remove optional closing tags (like </li>), rename classes, inline small CSS files, or defer scripts. Those are all higher-risk transforms that save a few extra percent at the cost of correctness edge cases. For those, use a build-time tool like html-minifier-terser with explicit configuration.
How to minify HTML
- Paste your HTML into the input panel.
- Read the minified output on the right — the size-saved percentage shows underneath.
- Copy or download the compressed HTML for deploy.
- Verify in a browser — minified HTML should render identically to the source.
Features
- Strips comments and collapses redundant whitespace.
- Preserves
<pre>,<code>,<textarea>,<script>,<style>content verbatim. - Live size-saved percentage.
- Copy to clipboard or download as .html.
- Runs in your browser — HTML source never uploads.
Frequently asked questions
- How much does minification save?
- 20–30% for normal hand-written HTML, 40–50% for heavily-commented templated HTML. Already-minified output from modern frameworks saves less than 10%.
- Does minification affect SEO?
- Positively. Smaller HTML means faster LCP (largest contentful paint), which is a Core Web Vitals ranking signal. Content and meta tags are not changed.
- Are scripts and styles affected?
- No. Content inside <script>, <style>, <pre>, <code>, and <textarea> is preserved verbatim because whitespace there is meaningful. To minify scripts/styles, use our JavaScript Minifier or CSS Minifier separately.
- Will minification break my page?
- This minifier uses conservative rules that keep HTML structurally identical. We don't remove optional closing tags, rename classes, or reorder attributes — those are higher-risk operations. If you need aggressive minification, configure html-minifier-terser in your build.
- Should I minify in production?
- Yes, almost always — unless the HTML is already served through a CDN that minifies automatically. Combined with gzip/brotli compression, minification saves bandwidth and improves load time.