HTML Minifier
Minify HTML by removing comments and collapsing whitespace between tags and inside tags to reduce document size.
HTML Minifier tool
Example
Input: <div> / <!-- note --> / <p>Hello <b>world</b></p> / </div>
Result: <div><p>Hello <b>world</b></p></div>
The comment and the line breaks between tags are removed and repeated spaces inside text collapse to one. Content of pre, textarea, script and style is kept as is.
- Paste your full HTML document or HTML snippet into the HTML panel.
- Comments are removed and whitespace is collapsed automatically - there are no settings to configure.
- View the minified HTML output generated instantly in the Minified HTML panel.
- Preview the result in your page to confirm spacing between inline elements looks the same.
- Click the copy button to copy the minified HTML for use in your production pages or email templates.
Minifying HTML Without Breaking Layout
An HTML minifier shrinks a page by removing comments and extra whitespace between and inside tags. A div holding a comment and a paragraph spread over four lines becomes <div><p>Hello <b>world</b></p></div>, and the page looks the same. Whitespace in HTML is tricky. Between block elements such as div, p, li or table cells it never shows, so the tool removes it. Between inline elements such as a, span or b, a space can be visible, so runs of spaces and line breaks are collapsed to one space rather than deleted. Inside tags, extra spaces around = and before > are tidied, while quoted attribute values stay exactly as written.
Some content must not change at all. The contents of pre, textarea, script and style elements are kept byte for byte. Internet Explorer conditional comments, such as <!--[if IE]>, are kept too, because some email clients still read them. Optional closing tags and attribute quotes are left in place, so the structure of your markup does not change.
The right-hand panel also works backwards: paste minified HTML there to get an indented, readable version. The tool does not compress the CSS or JavaScript inside style and script tags. Run those through the CSS Minifier and the JavaScript Minifier. To show HTML code as text on a page, escape it with HTML Entity Encode and Decode.
Frequently Asked Questions
Related Tools
CSS Minifier
Minify CSS by removing whitespace, comments, and redundant code to reduce file size.
Developer ToolsJavaScript Minifier
Minify JavaScript by removing whitespace, line breaks, and comments for smaller files, without renaming your code.
Developer ToolsHTML Entity Encode and Decode
Convert special characters to HTML entities and decode HTML entities back to readable text.
Developer ToolsJSON Minifier
Minify JSON by removing whitespace and formatting for compact, production-ready output.
Developer Tools