FormatterHQ

HTML Minifier

Compress HTML by collapsing whitespace, removing comments and redundant attributes, and minifying inline <style> and <script> blocks.

Input HTML
Output HTML
Ready.

How to use the HTML Minifier

  1. Paste your HTML into the Input editor, or use Sample, Upload file or Load URL to minify a page.
  2. Choose whether to Minify inline CSS, Minify inline JS and Remove attribute quotes.
  3. Press Minify; the status bar shows the size saved.
  4. Use Copy or Download above the output panel to take the minified HTML with you.

What the HTML minifier does

This HTML minifier uses html-minifier-terser, a widely used HTML compressor, to remove everything the browser does not need: indentation, line breaks, comments, default attribute values and verbose syntax. Inline CSS is normally minified with clean-css and inline JavaScript with Terser. The result is a smaller document that renders the same, useful for static sites, email templates, embedded widgets and server-rendered pages.

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "...">
<html>
  <head>
    <!-- page styles -->
    <style type="text/css">
      .hero { margin: 0px; color: #ffffff; }
    </style>
  </head>
  <body>
    <form method="get">
      <input type="text" disabled="disabled" class="" value="">
      <button type="submit" id="go">Go</button>
    </form>
    <script type="text/javascript">
      function hello(name) { console.log('Hello ' + name); }
    </script>
  </body>
</html>
<!doctype html><html><head><style>.hero{margin:0;color:#fff}</style></head><body><form><input disabled> <button type="submit" id="go">Go</button></form><script>function hello(l){console.log("Hello "+l)}</script></body></html>

Here the minifier shortened the doctype to <!doctype html>, removed the comment, dropped type="text/css" and type="text/javascript" (defaults in HTML5), removed method="get" and type="text" (also defaults), collapsed disabled="disabled" to disabled, removed the empty class and value attributes, and minified the inline CSS and JavaScript. A single space between the input and the button survived because it is visible on the page.

Options explained

  • Minify inline CSS – compresses <style> elements and style attributes. If a <style> block uses syntax clean-css cannot read (CSS nesting, @scope, @starting-style or a statement such as @layer a, b;), the <style> blocks of that document only lose their whitespace and comments, and style attributes are left as written.
  • Minify inline JS – compresses <script> elements and event handler attributes with Terser. Turn it off if a script uses syntax that should not be touched, such as template placeholders.
  • Remove attribute quotes (off by default) – drops quotes where HTML allows it: href="/about" becomes href=/about, while values with spaces like class="nav-link active" keep them. It is valid HTML, but some XML-based tools and email clients handle unquoted attributes poorly, so enable it only for pages served as regular HTML.

Whitespace: what is safe to remove

Collapsing whitespace is the biggest saving, but HTML whitespace is not always insignificant. The minifier keeps content inside <pre> and <textarea> unchanged, and between inline elements it reduces runs of spaces to a single space instead of removing them, so Hello <b>big</b> world becomes Hello <b>big</b> world. Layouts that rely on the gap created by whitespace between inline-block elements may still shift slightly; check such pages after minifying.

Common problems

  • "Parse Error" – the markup has a broken tag, such as an unclosed <span. Find it with the HTML Validator.
  • Template syntax ({{ }}, <?php ?>, {% %}) can be damaged if it appears inside inline scripts. Minify the rendered output instead, or disable inline JS minification.
  • Conditional comments for old Internet Explorer (<!--[if IE]>) are kept, because they contain markup; ordinary comments are removed.

When to minify HTML

Minified HTML is also convenient when markup has to live inside a JSON value or a JavaScript string, where every line break would otherwise need escaping. For server-rendered pages, compression with gzip or Brotli already removes most of the cost of whitespace, so HTML minification typically saves a few extra percent. The gains are larger for pages with many comments or big inline scripts, for HTML embedded in JavaScript strings, and for email templates where message size limits matter. For development, keep the readable source and format it with the HTML Formatter. Minification runs in your browser; nothing is uploaded.

Frequently asked questions

Is it safe to remove attribute quotes?
It is valid HTML5 when the value has no spaces or special characters, and the minifier only removes quotes in those cases. It is off by default because some non-browser tools expect quoted attributes.
Does the HTML minifier change my inline JavaScript?
With Minify inline JS on, scripts are compressed with Terser, which shortens local names and removes whitespace while keeping behavior. Turn the option off to leave scripts exactly as written.
Why was type="text" removed from my input?
text is the default type of an input element, so the attribute is redundant. The same applies to method="get" on forms and type="text/javascript" on scripts.
Will minifying break my layout?
Rarely. Whitespace inside pre and textarea is kept, and spaces between inline elements are reduced to one rather than removed. Designs that depend on exact whitespace between inline-block elements are worth checking.
Can I minify HTML that contains PHP or Blade code?
It is safer to minify the rendered HTML. Template code inside attributes or scripts may be treated as text or JavaScript and altered.

Last updated October 3, 2026

Related tools

JSON Minify Minify JSON by removing whitespace and line breaks. Shrink payloads for APIs, storage and embedding, and see the bytes saved. CSS Minifier Minify CSS online: remove whitespace and comments and merge rules to reduce stylesheet size. JavaScript Minifier Minify JavaScript online with Terser to shrink file size for faster websites. XML Minify Minify XML by removing indentation, line breaks and comments. Shrink SOAP payloads, sitemaps and configs while keeping them valid. Pug to HTML Converter Compile Pug templates to HTML online: tags, #id/.class shortcuts, attributes, block text, interpolation and comments. Responsive Website Tester Preview any website on phone, tablet, laptop and desktop screen sizes side by side to check your responsive design. Text to HTML Converter Paste formatted text from Word, Google Docs or a web page, or type plain text, and get clean HTML code. Removes inline styles, classes and Word markup. Word to HTML Converter Convert Word .docx documents to clean, semantic HTML with headings, lists, tables, links and images — right in your browser. BBCode to HTML Converter Convert forum BBCode such as [b], [url], [quote], [list] and [code] into clean, safe HTML markup instantly. Code Syntax Highlighter Highlight source code as self-contained HTML with inline styles - paste the coloured snippet into blogs, e-mails or docs. HTML Entities List Searchable list of 1,400+ named HTML character entities with decimal and hex codes, code points and CSS escapes. Click to copy. HTML Formatter Beautify or minify HTML online. Fixes indentation of tags, inline CSS and scripts.