Compact / compare / ship

HTML Minifier Online

Paste HTML to remove comments and redundant whitespace and to compact the CSS in style blocks. You see the size before and after, and text in pre, textarea and script elements is kept exactly as written. Everything runs in your browser.

Size before and afterKeeps pre, textarea and scriptsNothing is uploaded
Try it here

Minify your HTML

Paste HTML or open a file, choose what to remove and select Minify HTML. The status line shows the size in bytes before and after.

Options

Inline JavaScript is kept as written apart from surrounding whitespace; use a JavaScript minifier for scripts. Conditional comments and comments that start with <!--! are kept. Keep your readable original: minified HTML is for delivery, not for editing.

HCODX / minified HTML
HTML minification

What HTML minification removes

Minification deletes characters the browser does not need to build the page: comments, indentation and repeated spaces.

Browsers collapse any run of spaces, tabs and line breaks in ordinary text into a single space, and they ignore whitespace between block-level elements entirely. Indentation that makes source readable therefore costs bytes without changing what visitors see. This minifier removes whitespace next to block-level elements, shortens other runs to one space, drops comments and compacts the CSS inside style blocks.

Some whitespace does matter. A space between two links or two inline-block buttons is visible, so it is kept as a single space. Text inside pre and textarea keeps every space and line break. Script contents are left alone because whitespace rules in JavaScript differ from HTML; a dedicated JavaScript minifier can shorten scripts safely.

Minification is not HTTP compression. It changes the source text, while gzip or Brotli are transfer encodings a server or CDN applies on the way to the browser. The two work together. A shorter document also does not guarantee a noticeably faster site: images, third-party scripts, fonts and network latency usually matter more, so measure the deployed page if speed is the goal.

Keep both copies

Edit the readable version and generate the compact one when you publish.

Exact byte counts

Sizes are measured as UTF-8 bytes, the way the file is stored and sent.

Private by design

The minifier runs inside this page; your HTML is not uploaded or kept.

Before and after

A header, minified

Output from this minifier with the default options. The source is 216 bytes; the result is 146 bytes, about a third smaller.

The comment and the indentation are gone, and the stylesheet is compacted to a single rule. The two navigation links are still separated by one space, because without it the words Home and Blog would touch on the page.

Savings on a real page depend on how much indentation and commentary it contains, and are usually smaller than in this tiny example. Run on the articles on this site, the minifier saves between 9 and 15 percent before HTTP compression; text-heavy pages with little indentation, such as our policy pages, shrink by only 3 to 5 percent.

Minifier input and output
<!-- Input: 216 bytes -->
<!-- Site header -->
<header class="site-header">
  <nav>
    <a href="/">Home</a>
    <a href="/blog/">Blog</a>
  </nav>
</header>
<style>
  /* Spacing */
  .site-header nav a {
    margin-right: 1rem;
  }
</style>

<!-- Output: 146 bytes -->
<header class="site-header"><nav><a href="/">Home</a> <a href="/blog/">Blog</a></nav></header><style>.site-header nav a{margin-right:1rem}</style>
Review

What to check after minifying

A smaller file is only useful when the page still works.

01

Words around inline tags

Check that spaces remain between adjacent links, spans and emphasized words, especially where CSS turns them into inline blocks.

02

Custom preformatted text

pre and textarea are protected automatically. Elements you style with white-space: pre in CSS are not, so review them or untick Collapse whitespace.

03

Scripts and templates

Look for errors in the browser console. Server-side template tags such as {{ }} or <?php ?> belong in a build pipeline that understands them.

04

IDs and relationships

Confirm that labels, IDs and ARIA attributes are intact. The minifier never renames them, but a quick test of the form or menu is cheap.

If something looks different, untick an option and minify again to find which step caused it.

Workflow

Where minifying fits in publishing

Minify the copy you publish, not the copy you maintain.

Finish the readable version Correct the markup and confirm the page works before compacting it; debugging minified code is slow.
Keep a copy Commit or save the readable file. Minified output is a build product you can always regenerate.
Minify and read the numbers Run the minifier and note the saving. A few percent may not be worth an extra manual step.
Preview and deploy Open the minified file in a browser, compare it with the original, then upload it to your host.

Many hosts and build tools can minify HTML on deploy. If yours does, use that setting instead of minifying by hand, so the readable source stays the single file you edit.

Questions

HTML minifier questions

No. The minifier is JavaScript that runs inside this page. Your HTML stays in your browser and is gone when you close the tab.

No. It processes markup and inline CSS only. It does not resize, re-encode or otherwise optimize image files, fonts or linked scripts.

No. Minification changes the source text; HTTP compression is applied when a server sends a response and is undone by the browser. Most hosts compress automatically, and you can use both.

This minifier keeps one space wherever spaces separate inline content and never touches pre or textarea. Elements styled with white-space: pre or pre-wrap in CSS are the exception it cannot detect, so check those or turn off Collapse whitespace.

No. Keep the readable source for maintenance and debugging, and treat the minified file as output you can regenerate at any time.

No. Smaller HTML can make pages a little faster, but rankings depend on content, relevance and many other signals. Treat minification as a modest performance step.

Unquoted values are only valid when they contain no spaces or special characters. The minifier checks each value before removing quotes, but quoted attributes are easier to read and process with other tools, and the saving is usually small.

Building the whole site?

Edit readable files in the HCODX editor, preview them live, and export the project as a ZIP when you are ready to publish.

Instant HTML Runner & Viewer with Live Preview

Need to run a short HTML, CSS and JavaScript snippet? The HTML Runner Online has a focused editing surface with live output.

Open HTML Runner Online