HTML Minifier

Compress HTML pages including inline CSS and JavaScript.

0 chars
0 words
0 lines
0 chars
0 words
0 lines

HTML Minifier – Minify HTML Online

The HTML minifier (also known as an HTML compressor) removes everything a browser does not need from your markup. It is powered by html-minifier-terser, a widely used minifier that also compresses inline <style> blocks and <script> tags. The savings are shown below the output.

What it removes and shortens

  • Whitespace between tags and repeated spaces in text are collapsed.
  • Comments are removed (conditional comments are respected).
  • Boolean attributes are shortened: checked="checked" becomes checked.
  • Redundant attributes such as type="text/javascript" on scripts and type="text/css" on styles are dropped.
  • Doctype is shortened to <!doctype html>.
  • Inline CSS and JavaScript are minified with the same engines as the CSS and JS minifiers.

Options

  • Remove comments and Collapse whitespace – the two biggest savings, on by default.
  • Minify inline CSS / JS – compress <style> blocks, <script> blocks, style attributes, and event handlers.
  • Remove optional tags – drops tags the HTML spec allows you to omit, such as </li>, </p>, <head>, and <body>. Valid HTML, but some tools that parse HTML as XML will not like it.
  • Remove attribute quotes – class="a" becomes class=a where it is safe.

When to minify HTML

Minify static pages, email templates (carefully — some email clients are picky), landing pages, and HTML fragments embedded in JavaScript. For server-rendered sites, minification usually happens in the build or at the CDN.

Whitespace caution

Collapsing whitespace can remove a visible space between inline elements in rare cases. Content inside <pre> and <textarea> is never changed.

Make minified HTML readable with the HTML Beautifier, and minify external files with the CSS Minifier and JS Minifier.

Frequently Asked Questions

Yes. With the inline options enabled, <script> and <style> contents, style attributes, and inline event handlers are minified with Terser and clean-css.

The default options are safe for standard HTML. Removing optional tags or attribute quotes is valid HTML but may confuse tools that expect XHTML. Whitespace between inline elements can occasionally change.

You can, but test the result in your email clients. Keep comments off only if you don't rely on conditional comments for Outlook.