HTML Minifier
FREE TOOL · NO SIGN-UP
An HTML minifier removes the characters a browser does not need, such as comments, indentation and line breaks, so your markup gets smaller without changing what the page shows. Paste HTML into the tool above, choose which cleanups to apply and click Minify HTML. You get the compressed code, the input and output character counts and the percentage saved, ready to copy or download as index.min.html.
What HTML Minification Removes
Developers format HTML for people: nested tags are indented, sections are separated by blank lines and comments explain what each block does. Browsers ignore almost all of that. HTML minification strips it out so fewer bytes travel over the network.
This minifier handles three jobs, each with its own checkbox:
- Remove comments. Deletes standard HTML comments. Old Internet Explorer conditional comments (the ones that start with “if”) are kept, because some legacy templates still depend on them.
- Collapse whitespace. Turns runs of spaces, tabs and line breaks into a single space, and removes whitespace between tags entirely.
- Remove default type attributes. Drops type=”text/javascript” from script tags and type=”text/css” from style tags. Browsers treat these as the default, so the attribute is redundant.
The tool also tidies spacing inside tags, so an opening tag spread across several lines becomes one line. Inline script and style blocks are trimmed of leading indentation but their code is not minified. For that, run them through the JavaScript Minifier and the CSS Minifier.
Why Whitespace in HTML Can Matter
Most whitespace in HTML is meaningless to the browser, but not all of it. Inside some elements, spaces and line breaks are content. Between inline elements, a single space can be the gap between two words on screen. A safe minifier has to know the difference.
Pre, textarea and inline elements left untouched
The minifier leaves the contents of pre and textarea elements exactly as written. These elements display whitespace literally, so collapsing it would break code samples, poems or prefilled form text.
Script and style blocks are also protected from whitespace collapsing inside the code; only leading indentation on each line is removed.
Inline elements need more care. With “Collapse whitespace” on, the tool removes all whitespace between one tag and the next. In markup like <b>Free</b> <i>tools</i>, the space between the two tags disappears, and the words render as “Freetools”. Check paragraphs that place inline tags side by side, and if you see joined words, either untick “Collapse whitespace” or put the space inside one of the tags.
Attribute quotes and optional tags
Some aggressive minifiers remove quotes around attribute values and drop optional closing tags such as or
This tool does not do either. Attribute quotes stay, every tag you wrote stays, and the document structure is unchanged. The trade-off is slightly less compression for output that behaves like the original in every browser and is easy to read back if something goes wrong.
How to Minify Markup in Three Steps
Paste your HTML. Copy a full page, a template partial or a snippet into the HTML box. You can use the output of a page builder, an email template or a static site file.
Choose your options. All three options are on by default. Untick “Remove comments” if you need to keep developer notes or licence text, or untick “Collapse whitespace” if your layout relies on spaces between inline tags.
Click Minify HTML and copy the result. The stats panel shows input characters, output characters and the percentage saved. Click Copy to put the result on your clipboard or Download to save it as index.min.html.
Before replacing a live file, open the minified version in a browser and compare it with the original. Check navigation, forms, inline formatting and any embedded scripts. If you see an error message, the input probably contains a malformed tag that should be fixed in the source first.
Everything runs in your browser. The HTML you paste is not uploaded to a server.
How Much Smaller the File Gets
Savings depend on how the HTML was written. Hand-written templates with deep indentation and lots of comments shrink noticeably. Markup that is already compact, such as output from a framework that minifies by default, barely changes. The tool shows the exact percentage for your input, so you do not have to guess.
Keep the numbers in perspective. HTML is usually a small part of total page weight compared with images, fonts and JavaScript. Minifying a 40 KB document might save a few kilobytes, while compressing one hero image can save hundreds. Minification is worth doing because it is cheap and safe, but it is rarely the biggest speed win on a page.
The biggest gains come when minification is combined with server compression, covered below.
HTML Minification and SEO
Search engines read minified and formatted HTML the same way. Removing whitespace and comments does not change your content, headings, links or structured data, so it has no direct effect on rankings.
The indirect effect is page speed. Smaller HTML downloads faster, which can help time to first byte and the moment the browser starts rendering. Page experience, including Core Web Vitals, is something Google considers, but the effect of HTML minification alone is usually small.
Two cautions. First, if you minify by hand, do not accidentally remove structured data, meta tags or hreflang annotations. Second, a minifier that breaks markup can hurt SEO, for example by merging words in headings or corrupting inline JSON-LD. Always check the output.
Pairing Minification With Gzip and Caching
Minification removes characters. Compression, such as Gzip or Brotli, encodes the remaining bytes more efficiently during transfer. They work together: compression on its own already shrinks HTML a lot, and minified HTML compresses slightly better still.
Most web hosts and CDNs enable Gzip or Brotli automatically. You can confirm by checking the Content-Encoding header in your browser’s developer tools. If it is missing, ask your host or enable compression in your server configuration.
Browser caching is the third piece. Static HTML files can be cached by the browser or CDN so repeat visitors do not download them again. For dynamic pages, page caching at the server or CDN level saves the work of building the page on every request.
On WordPress, caching plugins often handle all three: minification, compression and caching.
Minification Mistakes That Break Layouts
Joined words between inline tags. The most common issue, explained above. Check bold, italic and link text that sits next to other tags.
Minifying broken HTML. Unclosed tags or stray angle brackets confuse any tokenizer. Validate or fix the source first.
Stripping comments a script needs. Some old plugins, templating systems and email clients rely on comment markers. Keep comments if you are not sure.
Editing the minified file. Make changes in the original source, then minify again. Hand-editing compressed markup leads to mistakes.
Double minification conflicts. Running a theme minifier, a caching plugin and a CDN minifier on the same page can produce odd results. Pick one.
Not testing forms and scripts. Inline event handlers and template syntax can behave differently once whitespace moves. Click through the page after deploying.
When to Automate in a Build Pipeline
An online HTML minifier is ideal for one-off jobs: an email template, a landing page, a widget snippet or a quick check of how much a file can shrink.
For sites you deploy often, automate it. Static site generators and build tools can minify HTML on every build using npm packages such as html-minifier-terser. WordPress sites can use a caching or performance plugin. Automation means you always edit readable source files while visitors always get compressed output, and nobody forgets the step.
Keeping the Original Source File
Never treat the minified output as your master copy. Keep the formatted original in version control or a backup folder, make all edits there and generate the compressed file from it. Minified HTML can be reformatted with a beautifier, but comments you removed are gone for good. Use the HTML Beautifier when you need to read compressed markup.
Lighter Markup for Faster Pages
Minify the HTML, then do the same for the rest of the page with the CSS Minifier and JavaScript Minifier, and check content balance with the Code to Text Ratio Checker. More free tools are in the FHSEO Hub free SEO tools collection.
