ShotMark
Skip to Content

HTML Minifier

Minify HTML by removing whitespace and comments.

HTML
Minified
Waiting for input

What is HTML Minifier?

An HTML minifier is a tool that removes whitespace, comments, optional tags, and redundant attribute quoting from HTML markup to produce a smaller document that browsers download and parse faster. The output renders identically to the source because none of the trimmed bytes affect the DOM tree the browser builds.

Frontend developers, performance engineers, and CMS template authors use an HTML minifier on every production deploy. A 14 KB hand-authored page typically drops below 9 KB after minification, and shrinks further to roughly 3 KB once Brotli compression runs.

Why use the HTML Minifier

  • Shrink documents by 20% to 40%. Removing whitespace and HTML comments alone trims a quarter of most server-rendered pages.
  • Faster initial render. Less markup means less time spent on byte streaming, HTML tokenization, and DOM construction before the browser can paint.
  • Lower CDN bandwidth. Marketing pages with millions of monthly views save real money per kilobyte trimmed.
  • Cleaner email and AMP payloads. Both formats penalize bloat, and email clients silently truncate documents over 102 KB in Gmail.

How to use the HTML Minifier

  1. Paste your HTML document or fragment into the input panel on the left.
  2. Click the Minify button at the top of the panel.
  3. Read the minified output in the right panel. Parser errors appear in red above the panels.
  4. Copy the result with the Copy button and paste it into your build output, template engine, or email body.

What gets removed

The HTML minifier applies safe transformations only. The DOM tree the browser constructs is identical to what the source produces.

PassActionTypical savings
Whitespace collapseReduces runs of spaces, tabs, and newlines between tags20-30%
Comment strippingRemoves <!-- ... --> including conditional comments5-10%
Attribute quote removalDrops quotes from safe values (class=btn vs class="btn")1-3%
Optional tag removalDrops </li>, </p>, </tr> where the spec allows1-3%
Boolean attribute shorteningRewrites disabled="disabled" to disabled0.5-2%
Empty attribute removalDrops style="" and class=""0.5-1%

Whitespace inside <pre>, <textarea>, <script>, and <style> blocks is preserved, since those contexts are whitespace-sensitive or have their own parsing rules.

Size savings example

Input (286 bytes):

<!-- Main navigation --> <nav class="primary-nav"> <ul> <li><a href="/home">Home</a></li> <li><a href="/about">About</a></li> <li><a href="/contact">Contact</a></li> </ul> </nav>

Minified output (151 bytes):

<nav class=primary-nav><ul><li><a href=/home>Home</a><li><a href=/about>About</a><li><a href=/contact>Contact</a></ul></nav>

Typical savings across page sizes:

InputRaw sizeMinifiedGzippedTotal reduction
Email template8 KB5.4 KB1.9 KB76%
Marketing landing page42 KB28 KB6.2 KB85%
Server-rendered listing page180 KB118 KB22 KB88%
Product detail page with SSR data320 KB210 KB38 KB88%

Common use cases

  • Server-rendered HTML responses. Next.js, Rails, Django, and Laravel templates all benefit from a minification pass before the response leaves the origin.
  • Email HTML templates. Strips comment annotations from MJML, Maizzle, or Foundation output that bloat the final send.
  • AMP pages. AMP requires inline CSS under 75 KB. Minification frees up room for actual styles.
  • Static site generators. Hugo, Eleventy, Astro, and Jekyll can pipe build output through the minifier for a smaller _site/ directory.

Frequently asked questions

Is minified HTML reversible?

The whitespace, comments, and dropped optional tags cannot be restored, since the information is not stored anywhere. An HTML prettifier can re-indent the markup for readability, but author comments are gone. Keep your source templates under version control.

Does minifying break my page?

No, as long as the minifier respects whitespace-sensitive contexts. The tool preserves text inside <pre> and <textarea> and leaves <script> and <style> blocks untouched. The rendered output is visually identical to the source.

What is the difference between minify and gzip?

Minification rewrites the HTML itself by removing characters and optional syntax, and the result is still valid HTML the browser can parse directly. Gzip and Brotli are binary compression layers the server applies before sending bytes over the wire. The two stack, and running both delivers roughly 88% total reduction.

Should I minify HTML in development?

No. Minified HTML is hard to read in the browser source viewer, breaks diff tools, and slows down debugging. Apply the HTML minifier only as part of your production build or response middleware.

Will the minifier strip my conditional comments for old IE?

By default, yes. Conditional comments (<!--[if IE]>...) look like normal HTML comments to the parser. If you still target legacy IE, configure the minifier to preserve them, or drop the IE workaround entirely.

Does minified HTML render faster?

Slightly. Browser parsers are fast, but smaller documents reach the parser sooner over slow connections and let the renderer start sooner. The transfer-time savings matter more than parse-time savings.

Can I minify HTML with inline <script> and <style>?

Yes. The HTML minifier leaves the contents of those blocks alone. If you also want to minify the inline JavaScript or CSS, run the relevant sub-tool on those blocks first, then minify the wrapping HTML.

Will minification remove my data attributes?

No. All data-* attributes are preserved, since they may be read by JavaScript at runtime. The minifier only drops attributes with empty values like class="" that have no effect on layout or behavior.

  • JavaScript Minifier - shrink JavaScript bundles by stripping whitespace and shortening identifiers.
  • CSS Minifier - strip whitespace and comments from CSS to shrink stylesheet bundles.
  • SQL Minifier - flatten multi-line SQL into a single line for embedded queries.
  • HTML Prettify - re-indent minified HTML for inspection and review.
Like this tool?

ShotMark captures what you do here, in one click.

The traces, payloads, and tests you run by hand? ShotMark grabs the whole bug and hands it to your AI agent.

Private beta accessFounding pricing lockNo spam ever