toolqik

175 · HTML & SEO

HTML Minifier

Shrink HTML by removing comments and whitespace, and minify the CSS and JavaScript inside it.

Runs in your browser
Whitespace
Remove
Minify
Minified HTML

  

About this tool

Minifying HTML removes everything the browser ignores: comments, indentation, line breaks between block elements and redundant attributes. This tool also minifies the CSS in <style> blocks and style attributes, the JavaScript in <script> blocks (with Terser) and inline JSON such as JSON-LD structured data. It shows the saving before and after gzip, which is what actually goes over the network.

Safe by default

The minifier never changes what the page displays:

  • Whitespace that renders is kept. A space between two inline elements (<b>bold</b> <i>italic</i>) shows on screen, so it stays. Whitespace next to block elements like <div> and <p> doesn’t, so it’s removed.
  • <pre> and <textarea> are untouched.
  • Conditional comments and <!--! … --> comments are kept, since they’re usually there for a reason.
  • SVG and MathML keep their self-closing tags and the case of attributes like viewBox.
  • Scripts that fail to parse are left as they are, with a warning, rather than being broken.

If you use CSS such as white-space: pre or display: inline-block on block elements, choose Collapse only, which turns runs of whitespace into a single space but never removes it.

Options explained

  • Default attributes: type="text/javascript" on scripts, type="text/css" on styles, method="get" on forms and type="text" on inputs are the defaults, so they can go.
  • Boolean attributes: disabled="disabled" and checked="" become disabled and checked.
  • Attribute quotes: class="nav" becomes class=nav when the value has no spaces or special characters. Valid HTML, but some people prefer to keep quotes.

How much does it save?

Hand-written pages usually shrink 10–25%, and pages with lots of indentation or comments more. After gzip or Brotli compression the difference is smaller, often 3–10%, because compression already handles repeated whitespace well. Minifying still helps: smaller files parse faster, and inline scripts and styles often shrink a lot.

FAQ

Is it safe to minify HTML?

With the default settings, yes: only whitespace the browser ignores is removed, and text inside <pre>, <textarea>, scripts that fail to parse and SVG is protected. Choose “Collapse only” if you rely on CSS white-space rules.

Does it minify inline JavaScript and CSS?

Yes. JavaScript in <script> blocks is minified with Terser, CSS in <style> blocks and style attributes with a CSS minifier, and JSON-LD is compacted. External files aren’t fetched.

Should I remove attribute quotes?

It’s valid HTML and saves a few bytes, but the saving after gzip is tiny. Leave it off if your tooling or team expects quotes.

Why is the gzip saving smaller?

Compression already shrinks repeated whitespace very well, so minifying saves less after gzip than before. It still reduces parse time and the size of inline scripts.

Is my HTML uploaded?

No. Minification, including Terser for JavaScript, runs entirely in your browser.

esc
↑↓ navigate↵ open