HTML Minifier – Compress HTML Safely in Your Browser

Paste HTML or drop .html files to minify them with html-minifier-terser. The tool collapses whitespace, removes comments and redundant attributes, shortens the doctype and minifies inline CSS and JavaScript, while leaving whitespace inside pre and textarea elements untouched. Choose Safe, Balanced or Max, compare the result with a diff view, measure gzip and brotli sizes and process several files at once. Everything runs in your browser and nothing is uploaded.

Your code

Paste code, or drop files here. Engines load only when you press the button.

Preset

Safe makes only changes that can't alter behaviour; Max squeezes harder (e.g. top-level mangling for modules).

Result

Files

.js .mjs .css .html .htm .svg .json — several at once for a batch
Engines and licenses

This tool uses these open-source engines, loaded only when needed:

100% in your browser: your code is processed on this device and never uploaded.

How to use the HTML minifier

  1. Paste your HTML or drop .html or .htm files.
  2. Choose a preset: Safe for templates you’re unsure about, Balanced for most pages, Max for the smallest output.
  3. Keep license comments on if your markup contains notices you must keep.
  4. Press Minify and copy or download the result.
  5. Check the diff and the gzip and brotli sizes to see what changed.

How it works

The HTML is parsed into elements, attributes and text, then written back out with these changes:

Change Safe Balanced Max
Collapse whitespace to one space yes yes
Remove comments (except <!--! … --> when kept) yes yes yes
Remove redundant attributes (e.g. type="text/javascript") type attributes only yes yes
Collapse boolean attributes (disabled="disabled" → disabled) no yes yes
Minify inline CSS and JS no yes yes
Sort attributes and class names no no yes

Text inside pre and textarea is never changed.

Worked examples

  • An indented page with comments: comments disappear, indentation collapses and <script type="text/javascript"> becomes <script>.
  • A code sample in <pre> keeps every space and line break.
  • Minifying again gives the same or a smaller result, so it’s safe to re-run.

Tips and common mistakes

  • Template syntax: if your HTML contains server-side or framework template tags, use Safe and check the result, as unusual syntax may not parse cleanly.
  • Inline whitespace matters: words separated only by a line break in the source still need a space. Safe keeps one, and Balanced keeps spaces between inline elements where they affect layout.
  • Use compression too: gzip or brotli on your server saves far more than minification alone.
  • Automate for production: minify in your build so every deploy is optimized.

Why use this minifier

Everything happens in your browser, presets explain exactly what changes, pre and textarea content is protected, and you get diff, batch, ZIP and real compression numbers in one accessible tool.

What it won’t change

The minifier never rewrites the text your visitors read, the order of elements or the content of pre and textarea, and it doesn’t touch external files referenced by your page.

Frequently asked questions

Can minifying HTML break my page?

Rarely, and the presets are designed to avoid it. Safe keeps a single space where whitespace was collapsed, so inline elements don't run together, and leaves inline scripts and styles alone. Max also sorts attributes and class names for better compression, which is harmless for valid HTML.

Is whitespace in <pre> and <textarea> kept?

Yes. Whitespace inside pre and textarea is meaningful, so it is always preserved exactly.

Are conditional or license comments kept?

Comments starting with ! are kept when Keep license comments is on. Other comments are removed.

Does it minify inline CSS and JavaScript?

Yes, with Balanced and Max. Style elements and attributes are minified as CSS, and script elements as JavaScript. Safe leaves them unchanged.

Is my HTML uploaded?

No. The minifier runs in a background worker in your browser and is loaded only when you press Minify.

How much will I save?

It depends on how much indentation, comments and inline code the page has. Typical hand-written pages shrink by 10–25% before compression; the tool shows the exact saving and the gzip and brotli sizes.

Sources