The HTML Minifier removes comments and collapses the whitespace HTML does not need, so a page or email template weighs less before it ships. Paste your markup and get a compact version back, with the size saved shown in bytes. The contents of pre, textarea and script elements and your quoted attribute values are left exactly as written, and everything runs in your browser.
Made for developers. Typical uses:
A 179-byte snippet with a comment, a heading, a paragraph with bold and italic text, a pre block and a style block minifies to 139 bytes, about 22% smaller. The comment disappears, the style block becomes .a{color:red}, the space between the bold and italic words stays, and the pre block keeps its indentation.
It works on one pasted document and does not fix invalid markup or remove optional tags. Layouts that depend on the gaps between inline-block elements can shift slightly, so always check the page. The saving shown is raw size; servers usually compress HTML in transit anyway.
Accuracy: Output is tested to keep behaviour unchanged. Keep your original files and test the minified version before you deploy it.
Expert Tip
If a row of inline-block elements looks different after minifying, give the elements explicit margins instead of relying on the whitespace between tags.
The HTML Minifier makes a page or email template smaller by removing comments and collapsing whitespace. You paste the markup, choose whether to remove comments and whether to minify style blocks, press Minify, and read the size before and after. The result can be copied or downloaded as minified.html. It runs in your browser and the markup is not uploaded.
A 179-byte snippet contains a page comment, a div with a heading, a paragraph with bold and italic text, a pre block with two indented lines, and a style block. The minifier returns 139 bytes, a saving of about 22 percent: the comment is removed, the whitespace between block elements such as div, h2, p and pre is deleted, the style block becomes .a{color:red}, and a single space is kept between the bold and italic elements so the words do not run together. The pre block is left exactly as written, including its two leading spaces on the first line and four on the second.
Whitespace is meaningful in some places in HTML, so the tool is careful. The contents of pre, textarea and script elements are left exactly as written, and quoted attribute values are not changed. A single space is kept between inline elements, because removing it would join words. Conditional comments used for old versions of Internet Explorer are kept when comment removal is on. The tool does not remove optional closing tags, quotes around attributes or other things that are valid but change how the markup looks to a human reader.
Most pages look identical after minifying, but layouts that rely on the whitespace between inline-block elements can shift. A row of inline-block buttons, for example, has small gaps made by the spaces between tags. After collapsing, one space remains, and between block-level elements none does. Always open the minified page before you publish it. If a gap changes, give the elements explicit margins instead of relying on spaces.
By default, the contents of style blocks are minified too. Switch the checkbox off if you want them untouched. Script contents are always left as written, so run scripts through the JavaScript Minifier and stylesheets through the CSS Minifier separately. To make minified HTML readable again, use the HTML Formatter. Compare the savings with the other things that slow a page, such as large images, which the guide to compressing images for faster websites covers, and see how to minify CSS, JavaScript and HTML for the full picture.
The tool works on one pasted document. It does not fix invalid markup, so check the HTML with the HTML Validator first. The saving shown is raw size, and servers usually compress HTML in transit anyway, so the difference over the network is smaller than the figure suggests. Keep your original markup as the version you edit.
What minifying removes, how much it saves next to gzip and Brotli, and how to test minified CSS, JavaScript and HTML before you deploy it.
Explore more in Minifiers, read the guides and articles, or see how we test our tools.
Format and beautify messy HTML code with proper indentation.
Best for beautifying minified HTML for editing
Minify and compress CSS stylesheets to reduce file size.
Best for shrinking a stylesheet before deploying it to a production website to reduce load time
Minify and compress JavaScript code to reduce file size.
Best for reducing JS file sizes for faster page loading
Validate HTML code for syntax errors and compliance.
Best for checking HTML for errors before deployment
Minify XML data by removing whitespace and comments.
Best for shrinking an XML API response before storing it in a database column
Minify and compress SVG files to reduce file size.
Best for optimizing SVG icons for website performance