HTML Minifier

Paste HTML to remove comments and redundant whitespace and to minify inline CSS and JavaScript. Content inside <pre> and <textarea> is left exactly as written.

Runs in your browserNo sign-upNothing uploaded

Minified output

How to use the HTML Minifier

  1. Paste an HTML document or fragment, or open an .html file.
  2. Choose what to remove: comments, whitespace, and whether inline <style> and <script> blocks should be minified too.
  3. Check the warnings line: an inline script with a syntax error is kept unchanged rather than breaking your page.
  4. Copy the minified HTML or download it.

What gets removed?

  • Comments: <!-- … --> is removed, except Internet Explorer conditional comments and comments starting with <!--!.
  • Whitespace between block elements: newlines and indentation between tags like <div>, <li> or <head> never render, so they are dropped completely.
  • Runs of spaces in text: they collapse to a single space, which is exactly how the browser renders them anyway.
  • Whitespace inside tags: <p class = "a"> becomes <p class="a">.

What is preserved?

Whitespace is significant in some places, and the minifier respects them. Content of <pre> and <textarea> is kept byte for byte. A single space between inline elements, such as <b>bold</b> text, is kept because removing it would join the words. Attribute values and quotes are never changed.

Inline CSS and JavaScript

Inline <style> blocks are optimized with CSSO and inline <script> blocks with Terser, the same engines used on the CSS minifier and JavaScript minifier pages. JSON-LD and other JSON script blocks are compacted, and scripts of unknown types (for example templates) are left alone.

Is HTML minification worth it?

For server-rendered pages and static sites the HTML document is the first thing the browser downloads, so every saved byte shortens time to first render. Savings of 10–25% before compression are common, more for heavily indented templates and pages with large inline scripts.

Frequently asked questions

Will minifying HTML change how my page looks?
No. Only whitespace the browser would collapse anyway is removed, and <pre>/<textarea> content is untouched. If you style elements with white-space: pre in CSS, turn off Collapse whitespace.
Does it minify inline JavaScript and CSS?
Yes, when the options are enabled. If an inline block has a syntax error it is kept unchanged and a warning is shown, so the page never breaks.
Can I minify template files such as Handlebars, Jinja or Blade?
Usually yes, as long as template tags appear in text or attribute values. Templates that put logic inside tag names or between attributes may need a manual check.
Is my HTML sent anywhere?
No. Everything is processed locally in your browser.

Related tools