πŸ“¦

HTML Minifier

βœ“ Free & no signup πŸ”’ Runs 100% in your browser Updated 2026-11-25 Website Management Tools

A typical HTML page carries a hidden tax: indentation spaces, line breaks between tags, and comments that made the file readable to humans but mean nothing to the browser. Stripping them is standard practice before deployment, because every byte between the opening doctype and the closing html tag is downloaded by every visitor. The minifier removes comments and inter-tag whitespace, collapses runs of spaces inside text, and reports exactly how many bytes you saved, live in the output panel.

Paste your HTML and the compacted result appears immediately. The tool runs entirely in your browser, so unreleased pages, client templates, and markup containing private text stay on your machine. There is no signup, no cost, and no file-size gate beyond your device's memory; it works the same on a phone as on a workstation.

What gets removed is deliberate. HTML comments disappear. Whitespace that exists only between tags, where it has no rendering effect, disappears. Runs of spaces inside text collapse to a single space, and leading or trailing whitespace on text nodes is trimmed. Nothing else changes: tags, attributes, attribute values, text content, and the contents of pre, textarea, script, and style blocks are preserved byte for byte.

What the Minifier Removes, Precisely

HTML is forgiving about whitespace, but not uniformly, which is why a careful minifier distinguishes three situations. Whitespace between two block-level tags has no visible effect and can be deleted outright. Whitespace inside flowing text is significant: browsers collapse runs of spaces to one, but one space must remain, and deleting it would glue words together. Whitespace inside pre and textarea is content and must never be touched.

SituationExampleAction
Between block tags> newline <div>Removed entirely
Inside text runsfast   shipping with double spacesCollapsed to one space
Leading/trailing text whitespace> Welcome to the store <Trimmed at the edges
Inside pre, textarea, script, styleIndented code samplePreserved byte for byte
Comments<!-- sidebar starts here -->Removed entirely

The edge case worth knowing is the inline-block gap. Two adjacent inline elements separated by whitespace render with a visible space, and that space is sometimes doing layout work, for example between inline-block buttons or list items styled as a horizontal menu. A minifier that deletes inter-tag whitespace indiscriminately would make those elements touch. This tool collapses such whitespace to a single space where it sits between text-bearing inline content, so the rendered spacing survives; pure block-to-block gaps, which render nothing, are removed completely.

How Much Can You Save?

Savings depend on how the source was written. Hand-formatted HTML with generous indentation saves the most; output from a framework that already emits compact markup saves little. Realistic numbers from representative documents:

DocumentBeforeAfterSaved
Marketing landing page, hand-coded, 2-space indent24,600 bytes19,300 bytes21 percent
Blog article page with long prose31,000 bytes27,400 bytes12 percent
Framework-rendered page, already compact45,200 bytes42,100 bytes7 percent
Email template with heavy indentation16,800 bytes13,000 bytes23 percent

An honest caveat belongs right next to these numbers: minifying HTML is not a substitute for server compression. Gzip or Brotli, applied by your web server or CDN, typically shrinks HTML by another 70 to 80 percent, and compressed transfer is what actually reaches the visitor's connection. Minification and compression stack, though: removing bytes before compression also removes bytes from the compressed stream, and comment-heavy or deeply indented pages compress measurably worse than clean ones. Think of minification as making the input to compression smaller and more repetitive, not as replacing it.

How to Use the Minifier (Step by Step)

  1. Paste the HTML you want to compact. Minification runs live, and the byte savings appear alongside the output.
  2. Skim the result for anything that should have survived: conditional comments or commented-out markup you still need are the usual suspects, since comments are removed.
  3. Copy the output into your build output, template file, or deployment pipeline.
  4. Keep the formatted original as your source of truth; minify from it every time you deploy, rather than editing the minified version.

The Deployment Workflow Angle

The healthy pattern is two versions of every template: a readable source file in your repository and a minified artifact at deploy time. Editing minified HTML directly is a mistake you only make once; with comments gone and indentation flattened, a one-character edit is easy to get wrong and hard to review. If you receive minified HTML from someone else, run it through the paired beautifier first, make your changes, and minify again before shipping.

Conditional comments, historically used to serve special markup to old browsers, are parsed as ordinary comments by this tool and will be removed. Modern pages almost never rely on them, but if a legacy template does, check the output for lost blocks. The same scrutiny applies to comments that document template sections; move those notes into the source repository or a separate document before minifying, because they will not survive the pass.

Round Trips and What Minification Does Not Do

Minification is not information-preserving in the strict sense: comments and indentation are gone and cannot be recovered from the output. That is why the readable original matters. The reverse direction, beautifying a minified file, restores structure and line breaks but cannot restore comments that were already stripped, which is a one-way street worth remembering before you delete a source file after minifying it.

The tool also does not do the aggressive tricks that dedicated build-time minifiers perform: it does not rewrite tag names, strip optional closing tags, remove quotes from safe attribute values, or shorten class names. Those transformations save additional bytes but interact subtly with CSS and JavaScript, and they belong behind a tested build pipeline, not a quick browser tool. What this tool removes is the safe, reversible-with-a-beautifier subset: comments and whitespace.

Tips and Best Practices

  • Minify from a formatted source file as a build step, never hand-edit minified output.
  • Check for inline-block whitespace gaps after minifying; where spacing matters, use CSS to control gaps explicitly instead of relying on source whitespace.
  • Combine with server compression for the full win: minification trims the input, gzip or Brotli shrinks the transfer.
  • Preserve critical comments by extracting them before minifying, since they will not survive the pass.
  • Verify pre-formatted code samples after minification; their whitespace is preserved, but confirm your deployment copies the file, not a reformatted variant.
  • Use the byte-savings report to decide whether minification is worth wiring into your pipeline for a given template.

Frequently Asked Questions

How much smaller does HTML get after minification?
Typically 7 to 23 percent depending on how the source was written. A hand-coded landing page with generous indentation might drop from about 24,600 to 19,300 bytes, a 21 percent saving, while framework-rendered markup that is already compact might save only 7 percent. The tool reports exact before and after byte counts for your input. Keep in mind that server-side gzip or Brotli usually shrinks the result by another 70 to 80 percent on top of that.
Does minifying HTML break inline element spacing?
It can if whitespace between inline elements is deleted indiscriminately, because that space renders as a visible gap between inline-block items, such as buttons in a row. This tool collapses whitespace between text-bearing inline content to a single space so rendered spacing survives, and removes only pure block-to-block gaps that have no rendering effect. If your layout depends on precise gaps, control them with CSS margins rather than source whitespace so minification is always safe.
Is HTML minification a replacement for gzip compression?
No, and the two are not competitors. Compression happens at the server or CDN and typically shrinks HTML by 70 to 80 percent on the wire, while minification removes bytes before compression even starts. They stack: a minified document compresses slightly better because repetitive indentation and comments are gone. Run both for the best result, with minification as a build-time step and compression enabled in your server configuration, which is the standard production setup.
Why did my HTML comments disappear after minifying?
Removing comments is a core function of minification: comments are bytes that every visitor downloads and no visitor sees, and they often contain internal notes you would not want to publish anyway. Conditional comments for legacy browsers are also treated as ordinary comments and removed. If a comment is functionally important, such as a conditional block, extract it before minifying or exclude that template from the minification step, since the stripped text cannot be recovered from the output.
Does the minifier touch code inside pre, textarea, script, or style tags?
No. Whitespace inside pre and textarea is displayed content, so it is copied byte for byte; deleting it would visibly change code samples and default form values. Script and style interiors contain JavaScript and CSS, which follow their own formatting rules and are left untouched as well. The minifier only repositions the surrounding tags if needed. For compacting the embedded code itself, run it through the dedicated JavaScript or CSS minifier tools on this site.
Can I restore the original formatting after minifying HTML?
Partially. Running the result through an HTML beautifier restores indentation and line breaks, so the file becomes readable again, but anything minification removed is gone for good: comments, original indentation style, and blank lines cannot be recovered. This is why you should always keep the formatted source file in your repository and treat minified output as a disposable build artifact generated from it at deploy time, never as the editable master copy.

Related Tools