HTML Minifier - Compress HTML Code Free Online
Paste your HTML to remove comments, collapse whitespace, minify inline CSS and JavaScript, and strip optional quotes. A savings stats panel shows exact byte reduction and percentage.
Why HTML Minification Matters
Every unnecessary character in an HTML file costs bandwidth. For small personal sites this is trivial - but for high-traffic websites, the savings compound significantly. Google's Core Web Vitals guidelines explicitly include render-blocking resource size as a factor in Largest Contentful Paint (LCP) scoring, and HTTP archive data from 2025 shows that the median HTML page can be reduced by 15-25% through minification alone.
Minification removes four categories of characters that browsers process but discard: whitespace and line breaks (browsers collapse consecutive whitespace to a single space in rendered output), HTML comments (never rendered, purely for developer reference), optional attribute quotes (HTML5 allows attribute values without quotes when they contain no spaces or special characters), and the content of inline style and script blocks can be further compressed using CSS and JavaScript minification rules.
This tool applies all four techniques with individual toggles, so you can choose exactly which optimisations to apply. The inline CSS and JS minification options are particularly valuable for HTML templates that embed styling or scripting directly rather than using external files.
The Five Minification Techniques
Remove HTML comments - Strips all <!-- comment --> blocks from the HTML. IE conditional comments are preserved by default since they affect browser rendering. For most modern sites, all comments are safe to remove from production files.
Collapse whitespace - Replaces multiple consecutive spaces, tabs, and newlines with single spaces, and removes whitespace between HTML tags where it has no visual effect. This is typically the largest single contributor to file size reduction.
Remove optional attribute quotes - HTML5 permits attribute values without quotes when the value consists only of alphanumeric characters, hyphens, underscores, periods, and colons. For example, class="nav" can safely become class=nav. This option applies that transformation where safe.
Minify inline CSS - Applies CSS minification rules to content inside <style> tags: removes CSS comments, collapses whitespace around selectors and properties, and removes unnecessary spaces.
Minify inline JS - Strips JavaScript comments and excess whitespace inside <script> tags. This is a conservative minification - for production use, a dedicated JavaScript minifier like Terser produces better results for complex scripts.
How to Use the HTML Minifier
Choose your options
Select which minification techniques to apply. All five are available with individual toggles - enable Minify inline CSS and JS for maximum compression when your HTML includes embedded styles and scripts.
Paste your HTML
Copy your HTML source and paste it into the left input panel. The byte count updates as you type.
Click Minify or Ctrl+Enter
The minified output appears in the right panel. The stats bar shows original size, minified size, bytes saved, and percentage reduction.
Copy or Download
Click Copy to use in your clipboard, or Download to save as minified.html - ready for deployment.
Features
5 Minification Options
Comments, whitespace, inline CSS, inline JS, and optional quotes.
Savings Stats
Original size, minified size, bytes saved, and % reduction shown clearly.
Download Button
Save the minified file as minified.html with one click.
Ctrl+Enter
Keyboard shortcut for fast minification without reaching for the mouse.
Browser-Only
Your HTML never leaves your device.
Free & Unlimited
No account, no size limits.