Skip to content

HTML Minifier

Minify HTML by removing comments and collapsing whitespace between tags and inside tags to reduce document size.

HTML Minifier tool

Loading...

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.

  1. Paste your full HTML document or HTML snippet into the HTML panel.
  2. Comments are removed and whitespace is collapsed automatically - there are no settings to configure.
  3. View the minified HTML output generated instantly in the Minified HTML panel.
  4. Preview the result in your page to confirm spacing between inline elements looks the same.
  5. 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

Usually not. Whitespace between block elements never shows, and between inline elements the tool keeps one space. The rare exception is a layout that depends on the exact whitespace between inline-block elements, where the gap can shift slightly. Preview the minified page once before you publish it.
No. The contents of style and script elements are kept exactly as written, so a quirk in your code can never be broken by the HTML step. If you want those compressed too, run the code through a CSS or JavaScript minifier separately and paste it back in.
Comments like <!--[if mso]> or <!--[if IE]> ... <![endif]--> look like ordinary comments but carry instructions. Outlook for Windows still reads them in HTML email, so removing them can break an email layout. Every other comment is removed.
For most pages the saving is smaller than for CSS or JavaScript, especially once the server applies gzip or Brotli. It helps most on large server-rendered pages, long lists and HTML email, where size limits matter. It also removes developer comments you may not want visitors to see.

Related Tools

CSS Minifier

Minify CSS by removing whitespace, comments, and redundant code to reduce file size.

Developer Tools

JavaScript Minifier

Minify JavaScript by removing whitespace, line breaks, and comments for smaller files, without renaming your code.

Developer Tools

HTML Entity Encode and Decode

Convert special characters to HTML entities and decode HTML entities back to readable text.

Developer Tools

JSON Minifier

Minify JSON by removing whitespace and formatting for compact, production-ready output.

Developer Tools

Markdown to HTML Converter

Convert Markdown text to clean, semantic HTML. Supports headings, lists, links, images, code blocks, tables, and more.

Text and Writing

XML Formatter and Prettifier

Format, indent, and validate XML documents with customizable indentation and output options.

Developer Tools