HTML Minifier – Minify HTML Code Online
Make your HTML smaller and faster to load. Remove comments and unnecessary whitespace, minify inline CSS and tidy attributes — with safe defaults that keep preformatted text and scripts intact.
Paste your HTML and the minified version appears instantly with the bytes saved. By default the tool removes comments, collapses whitespace, minifies inline CSS, trims inline scripts and removes type="text/javascript" and type="text/css". Content in pre, textarea, script and style is protected. Copy or download the result.
How to use HTML Minifier
- Paste your HTML code.
- Choose which optimisations to apply.
- Check the size saving.
- Copy or download the minified HTML.
- Test the page before publishing.
What HTML minification does
HTML written by people and templates contains indentation, line breaks and comments that browsers do not need. Minification removes them so the file is smaller. The page looks and works the same, but fewer bytes have to travel over the network.
| Option | Effect |
|---|---|
| Remove comments | Deletes `<!-- … -->` but keeps conditional comments |
| Collapse whitespace | Turns runs of spaces and line breaks into one space; removes space around block tags |
| Minify inline CSS | Compresses the contents of style elements |
| Trim inline scripts | Removes leading and indenting whitespace in scripts |
| Remove default types | Drops type="text/javascript" and type="text/css" |
| Tidy attributes | Removes extra spaces inside tags |
How much does it save?
Typical savings are 10–30 % of the raw HTML size, more for heavily indented templates. With gzip or Brotli compression on the server the difference shrinks, because compression already handles repeated whitespace well — but minified files still compress a little better and parse slightly faster. For most sites, minifying HTML is a small, free win alongside bigger ones like compressing images with the Image Compressor.
Why whitespace needs care
In HTML, a space between inline elements is visible: `<b>bold</b> <i>italic</i>` shows a space between the words. This minifier keeps a single space between inline elements and only removes whitespace next to block elements like div, p, li and table cells, so text does not run together. Whitespace inside pre and textarea is never touched.
When to minify
Minify as the last step before deployment and keep your readable source files for editing. Many build tools and CMS plugins can do this automatically; this tool is handy for static pages, email templates, landing pages and checking what a minifier would change. Always test the minified page — especially if your scripts depend on exact whitespace.
Related tools
Minify stylesheets with the CSS Minifier & Beautifier, tidy JSON with the JSON Formatter, convert Markdown with Markdown to HTML Converter and escape URLs with URL Encode / Decode. Your code is processed in your browser and never uploaded.
You may also find these free tools useful: JSON Formatter, Password Generator and Regex Tester.
Frequently asked questions
What does an HTML minifier do?
It removes comments, extra whitespace and unnecessary attributes so the HTML file is smaller.
Is minified HTML safe?
Yes with safe settings. This tool protects pre, textarea, script and style content and keeps spaces between inline elements.
How much smaller will my HTML be?
Usually 10–30 %, depending on indentation and comments.
Does minifying HTML help SEO?
Indirectly: smaller pages load faster, which supports Core Web Vitals. Content and markup stay the same.
Is my code uploaded?
No. Minification runs entirely in your browser.
Last updated: