HTML Minifier
Shrink HTML by deleting comments and the indentation and line breaks that browsers ignore. The minifier is conservative: it collapses whitespace only where it cannot change how the page is displayed, leaves pre, textarea, script and style blocks byte for byte unchanged, and shows how many bytes you saved.
Minify Your HTML
Minified HTML
Size
How to Use the HTML Minifier
- Paste your HTML into the box.
- Choose whether to remove comments, keep conditional comments and collapse whitespace.
- Press Minify.
- Compare the sizes, then copy or download minified.html.
About This Tool
Developers preparing static pages or email templates, and site owners who want a smaller HTML payload without a build step.
Input: HTML · Output: Minified HTML (.html).
Features and Limitations
Features
- Removes HTML comments; conditional comments for old Internet Explorer can be kept.
- Collapses runs of whitespace to one space and removes whitespace around block-level tags, where it is never rendered.
- pre, textarea, script and style contents are copied exactly.
- Shows original size, new size and percentage saved; your markup is never rendered or run.
Limitations
- It does not rewrite attributes, remove optional tags or quotes, or minify the CSS and JavaScript inside style and script elements. Use the CSS Minifier or JavaScript Minifier for those parts.
- CSS such as white-space: pre on a normal element is not detected, so whitespace in such elements will be collapsed.
- A single space between inline elements is kept on purpose, so the saving is smaller than with aggressive minifiers.
- Text with a literal less-than sign that is not part of a tag is passed through unchanged.
- Results are computed in your browser; nothing you enter is sent to a server.
Example
A page with indented
lines and a comment shrinks by roughly a quarter to a half, depending on how much indentation it had. A
block inside stays identical.Frequently Asked Questions
Is it safe to minify HTML?
Collapsing whitespace can only matter where whitespace is rendered. This tool leaves a single space between inline content and removes whitespace only next to block-level tags and in pre, textarea, script and style it does nothing. Review pages that rely on white-space: pre-wrap in CSS.
What are conditional comments?
Comments such as were read by old Internet Explorer versions. Keep them if you still support those browsers; otherwise remove them.
Does it minify inline JavaScript and CSS?
No. Inline script and style blocks are left untouched to avoid breaking code. Minify them separately with the dedicated tools.
How much will I save?
It depends on how much indentation and how many comments your HTML has. Heavily indented templates often shrink by 20 to 50 percent.
Does it run my page?
No. The HTML is processed as text only.
Related Tools
More like this: all Format & Validate tools, all Developer & Web tools or the TinySandy home page.