HTML Minifier

Runs in browser Formatting

Compress HTML safely: collapse whitespace between tags, remove comments (except conditional ones), and optionally strip optional quotes — with size savings shown.

Privacy: This tool runs entirely in your browser. Your input never leaves your device.
Loading tool…

What does a formatter or minifier change in code?

A formatter changes layout — whitespace, line breaks and indentation — so that HTML, CSS or JavaScript reads consistently, and some also normalise details the language treats as equivalent, such as HTML tag-name case or attribute quotes; a minifier removes what the browser does not need — comments, whitespace, optional semicolons — and may rewrite values into shorter equivalents such as #fff for #ffffff. Neither is meant to change what the code does, but review the diff before you commit it: an option that reorders code, such as sorting CSS properties, can change which declaration wins, and a lower-cased tag name breaks a case-sensitive framework component such as <MyComponent>.

How to use HTML Minifier

  1. Paste the HTML.
  2. Toggle the options you want (quotes removal is off by default).
  3. Copy the compact result and check the size savings.

HTML Minifier features

  • Collapses whitespace between tags and inside text
  • Removes comments while keeping conditional (<!--[if IE]>) and <!--! comments
  • Optional removal of attribute quotes where HTML5 allows it
  • Minifies inline <style> and <script> blocks
  • Removes redundant attributes (type="text/javascript", type="text/css", method="get")
  • Never touches <pre> and <textarea> content

HTML Minifier example

Minify a snippet

Input:

<div class="a">
  <p>Hello   <b>world</b></p>
  <!-- note -->
</div>

Output:

<div class="a"><p>Hello <b>world</b></p></div>

Frequently asked questions about HTML Minifier

Is whitespace inside <pre> and <textarea> affected?

No. Those elements keep their content exactly; only whitespace between tags and inside regular text is collapsed.

Which comments are removed?

Regular <!-- comments --> are removed. Conditional comments (<!--[if IE]>) and comments starting with <!--! are kept when "Keep conditional comments" is on.

Is removing attribute quotes safe?

Quotes are only removed when the value contains no spaces, quotes, =, <, > or backticks, which is valid HTML5. Leave the option off if your toolchain requires quoted attributes.

Does it minify inline CSS and JavaScript?

Yes. <style> content goes through the CSS minifier and <script> content (JavaScript types only) through the JavaScript minifier.

References