HTML Minifier

Make your HTML smaller and faster to load. Remove comments and extra whitespace, minify inline CSS and JSON-LD, and shorten attributes, while keeping pre, textarea and script content exactly as it is.

  • Safe whitespace handling
  • Inline CSS & JSON-LD
  • Runs in your browser
–Original
–Minified
–Saved
–Minified + gzip

How to use the HTML Minifier tool

  1. Paste or open your HTMLPaste a page or template, or click “Open file” to load an .html file.
  2. Pick your optionsRemove comments, collapse whitespace, minify inline CSS and JSON-LD, and optionally remove attribute quotes.
  3. Check the resultThe minified HTML appears instantly with the size saved and the gzip estimate.
  4. Copy or downloadCopy the output or download it as a .min.html file.

What it does

  • Smart whitespaceRemoves whitespace between block elements and collapses it inside text, so spacing between words stays the same.
  • Protected contentpre, textarea and script contents are never changed, so code samples and form defaults stay intact.
  • Inline CSSMinifies <style> blocks and style="" attributes with the CSS minifier.
  • Structured dataCompacts JSON-LD schema markup while keeping it valid.
  • Conditional comments keptIE conditional comments and <!--! … --> comments are preserved.

Why minify HTML?

Every byte of HTML must be downloaded before the browser can start building the page. Removing comments, indentation and redundant attributes reduces page weight, often by 10–25%, which helps pages load faster on slow mobile connections and improves Core Web Vitals.

Options explained

OptionExample
Remove comments<!-- header --> is removed
Collapse whitespaceIndentation between tags is removed; Hello   world becomes Hello world
Remove default type attributes<script type="text/javascript"> → <script>
Shorten boolean attributeschecked="checked" → checked
Remove optional quoteslang="en" → lang=en (valid HTML5, off by default)

Is it safe?

The minifier is deliberately conservative. Whitespace between inline elements such as <b>, <a> and <span> is collapsed to a single space rather than removed, because removing it could join words together. Content of <pre>, <textarea> and <script> is copied exactly. Always test the minified page before deploying it, and keep your original source for editing.

Beyond minification

  • Enable Gzip or Brotli compression on your server for an even bigger reduction.
  • Minify your stylesheets with the CSS Minifier and scripts with the JavaScript Minifier.
  • Compress images with the Image Compressor; images are usually the heaviest part of a page.

Frequently asked questions

What does an HTML minifier do?
It removes comments, unnecessary whitespace and redundant attributes so the page is smaller but looks and works the same.
Will minifying HTML break my page?
This minifier keeps spaces between inline elements and never changes pre, textarea or script content, so pages render the same. Test before deploying.
Does it minify inline CSS and JavaScript?
Inline CSS and JSON-LD are minified. Inline JavaScript is left untouched for safety; use the JavaScript Minifier for scripts.
Can I minify a whole website?
This tool handles one page at a time. For whole sites, use a build tool or your CMS’s optimization plugin.
Is my HTML uploaded?
No. Everything runs in your browser.