Last updated ·Published ·By the WiserWork team

HTML Minifier

Minify HTML by removing comments, whitespace & unnecessary attributes

Original: 0 chars Minified: 0 chars Saved: 0%
Copied to clipboard!

HTML minification looks trivial until you remember that whitespace is content: this tool collapses the gaps between tags and shows you the character count it saved.

What is the HTML Minifier?

Markup carries two kinds of whitespace. Between block-level tags it is decorative and safe to remove; inside a text run, or inside a pre or textarea element, it is part of what the page actually displays. This minifier removes the gap between every closing and opening tag, collapses runs of two or more spaces into one, deletes line breaks entirely, and hand-scans the document for comment markers so that conditional comments beginning with an if test survive.

Key Features

  • Collapses whitespace between tags and deletes every line break
  • Character-by-character comment scanner that keeps conditional comments intact
  • Optional removal of the closing li, td, th, tr and option tags
  • Optional unquoting of simple attribute values made of letters, digits, hyphens
  • Live original, minified and saved counters plus a .min.html download

Common Use Cases

  • Compressing a single static landing page that no build tool ever touches
  • Squeezing an HTML email template down before pasting it into a sending platform
  • Reducing the size of an inline HTML snippet stored in a database field
  • Seeing how much of a generated page is indentation rather than markup

How to Use the HTML Minifier

  1. Replace the sample document in the HTML Input pane with your own markup.
  2. Keep Remove Comments and Remove Whitespace on unless you need comments preserved.
  3. Turn on Remove Optional Closing Tags only if the markup is HTML5, not XHTML.
  4. Watch the Saved badge to judge whether the reduction is worth shipping.
  5. Click Download .min.html to save the output, or Copy to take it elsewhere.

Tips for Best Results

  • Whitespace inside pre and textarea is real content, so minify those pages by hand instead
  • Line breaks vanish everywhere, which turns a double-slash comment in an inline script into a page-breaker
  • Unquoting attributes also rewrites quoted strings inside inline scripts, so check any script blocks
  • Servers already gzip HTML, so the real-world saving is smaller than the character count suggests

Why Use WiserWork's HTML Minifier?

The gap between two tags is usually pure formatting, and removing it is free bytes on every page view. Doing it here rather than in a build tool means you can eyeball the result on a page you only touch twice a year. It also means responsibility for checking pre blocks, textarea defaults and inline scripts is yours, because this is a set of pattern replacements, not an HTML parser.

Who Uses the HTML Minifier?

People maintaining static or hand-edited pages use it most: portfolio sites, documentation pages, one-off landing pages. Email developers reach for it too, since some sending platforms cap template size. So do developers pasting markup into a CMS field with a length limit.

Frequently Asked Questions

Is whitespace in HTML ever significant?

Yes, and that is the catch with any HTML minifier. Inside a pre element or a textarea, every space and line break is displayed literally, and a run of text needs one meaningful space between words.

Does this tool protect pre and textarea content?

No. It collapses whitespace across the whole document, so a code block inside a pre element will lose its indentation. Minify those pages carefully or leave the whitespace option off.

What happens to my inline script tags?

Their content is treated as ordinary text. Line breaks are removed, so a script using double-slash line comments ends up with everything after the first one commented out.

Are conditional comments preserved?

Yes. The comment remover scans character by character and leaves comments starting with an if test alone, so legacy Internet Explorer conditionals survive intact.

Is it safe to drop the closing li and td tags?

In HTML5, yes, because the parser infers them. It is not safe in XHTML or anything read by a strict XML parser, which is why the option ships switched off.

Which attribute quotes get removed?

Only values made entirely of letters, digits, hyphens and underscores. Anything containing a space, slash or colon keeps its quotes, since unquoting those would break the tag.

Will minifying help if my server already uses gzip?

A little. Gzip is very good at encoding repeated whitespace, so most of the saving is already there; minifying mainly removes what gzip would have to encode at all.

Does the tool validate my HTML?

No. It performs text replacements and never checks that tags are balanced. Malformed input simply produces malformed, smaller output.

Is my markup sent to a server?

No. Everything happens in the page you are on, and whatever you paste into the input box goes away when you close the tab.

Can I unminify the result?

Not here. Formatting is discarded rather than recorded, so keep the readable file as your source and treat the minified copy as a build artifact.

Minifying markup is worth doing on pages you ship by hand, as long as you know which whitespace matters. Check anything containing a pre block, a textarea or an inline script, then ship the smaller file.

Found this useful? Share it