HTML Minifier Online
Paste HTML to remove comments and redundant whitespace and to compact the CSS in style blocks. You see the size before and after, and text in pre, textarea and script elements is kept exactly as written. Everything runs in your browser.
Minify your HTML
Paste HTML or open a file, choose what to remove and select Minify HTML. The status line shows the size in bytes before and after.
Inline JavaScript is kept as written apart from surrounding whitespace; use a JavaScript minifier for scripts. Conditional comments and comments that start with <!--! are kept. Keep your readable original: minified HTML is for delivery, not for editing.
What HTML minification removes
Minification deletes characters the browser does not need to build the page: comments, indentation and repeated spaces.
Browsers collapse any run of spaces, tabs and line breaks in ordinary text into a single space, and they ignore whitespace between block-level elements entirely. Indentation that makes source readable therefore costs bytes without changing what visitors see. This minifier removes whitespace next to block-level elements, shortens other runs to one space, drops comments and compacts the CSS inside style blocks.
Some whitespace does matter. A space between two links or two inline-block buttons is visible, so it is kept as a single space. Text inside pre and textarea keeps every space and line break. Script contents are left alone because whitespace rules in JavaScript differ from HTML; a dedicated JavaScript minifier can shorten scripts safely.
Minification is not HTTP compression. It changes the source text, while gzip or Brotli are transfer encodings a server or CDN applies on the way to the browser. The two work together. A shorter document also does not guarantee a noticeably faster site: images, third-party scripts, fonts and network latency usually matter more, so measure the deployed page if speed is the goal.
Keep both copies
Edit the readable version and generate the compact one when you publish.
Exact byte counts
Sizes are measured as UTF-8 bytes, the way the file is stored and sent.
Private by design
The minifier runs inside this page; your HTML is not uploaded or kept.
A header, minified
Output from this minifier with the default options. The source is 216 bytes; the result is 146 bytes, about a third smaller.
The comment and the indentation are gone, and the stylesheet is compacted to a single rule. The two navigation links are still separated by one space, because without it the words Home and Blog would touch on the page.
Savings on a real page depend on how much indentation and commentary it contains, and are usually smaller than in this tiny example. Run on the articles on this site, the minifier saves between 9 and 15 percent before HTTP compression; text-heavy pages with little indentation, such as our policy pages, shrink by only 3 to 5 percent.
<!-- Input: 216 bytes -->
<!-- Site header -->
<header class="site-header">
<nav>
<a href="/">Home</a>
<a href="/blog/">Blog</a>
</nav>
</header>
<style>
/* Spacing */
.site-header nav a {
margin-right: 1rem;
}
</style>
<!-- Output: 146 bytes -->
<header class="site-header"><nav><a href="/">Home</a> <a href="/blog/">Blog</a></nav></header><style>.site-header nav a{margin-right:1rem}</style>What to check after minifying
A smaller file is only useful when the page still works.
Words around inline tags
Check that spaces remain between adjacent links, spans and emphasized words, especially where CSS turns them into inline blocks.
Custom preformatted text
pre and textarea are protected automatically. Elements you style with white-space: pre in CSS are not, so review them or untick Collapse whitespace.
Scripts and templates
Look for errors in the browser console. Server-side template tags such as {{ }} or <?php ?> belong in a build pipeline that understands them.
IDs and relationships
Confirm that labels, IDs and ARIA attributes are intact. The minifier never renames them, but a quick test of the form or menu is cheap.
If something looks different, untick an option and minify again to find which step caused it.
Where minifying fits in publishing
Minify the copy you publish, not the copy you maintain.
Many hosts and build tools can minify HTML on deploy. If yours does, use that setting instead of minifying by hand, so the readable source stays the single file you edit.
HTML minifier questions
Building the whole site?
Edit readable files in the HCODX editor, preview them live, and export the project as a ZIP when you are ready to publish.
Instant HTML Runner & Viewer with Live Preview
Need to run a short HTML, CSS and JavaScript snippet? The HTML Runner Online has a focused editing surface with live output.
Open HTML Runner Online