HTML Minifier

This HTML minifier compresses your markup. It collapses space between elements and removes comments. It works with care. A single space stays wherever it separates words across inline tags. The contents of pre and textarea stay untouched.

Your files never leave this device

Minify your HTML Live · Layout-safe

Comments

Turn this on if your build relies on conditional or marker comments.

How to minify HTML

  1. Paste your HTML into the box above.
  2. Leave Keep HTML comments off unless your build needs them.
  3. Read the minified output that appears right away.
  4. Check the saving in characters.
  5. Copy the result or download it.

What this HTML minifier gives you

  • Space between tags removed wherever it is safe.
  • One space kept between text runs so words never join.
  • Exact copies of pre and textarea content.
  • Collapsed space inside script and style with no code changes.
  • Comments removed by default with an option to keep them.
  • Tidy space inside tags with attribute values left alone.

Where the bytes hide in an HTML page

A formatted page carries a lot of indent. Think of a component inside a card inside a grid inside a section. That markup can sit ten or twelve levels deep. Each line then starts with about two dozen spaces. Across a few hundred lines that adds up.

Comments add more. Build notes and old blocks of commented code ship to every visitor. Generator banners do too. Every browser ignores all of them.

The mistake a careless HTML minifier makes

Some tools remove all space between tags. That breaks pages. Space between inline elements matters.

Take two links with a space between them for Terms and Privacy. Remove the space and the page shows "TermsPrivacy". This tool keeps a single space wherever text runs meet. It removes space only where no text sits on either side. It saves a little less than some tools. It never quietly changes how a page reads.

What the tool protects

PartWhat happens
pre and textareaKept byte for byte because the page shows the spaces
script and styleSpace collapsed but code never rewritten
Attribute valuesNever touched so class lists keep their spacing
Conditional commentsKept when you turn on the comments option

How much does HTML minification matter?

Be realistic. Almost every server sends pages with gzip or brotli. Those squeeze indents very well because indents repeat so much. So the real saving in transfer is modest. Expect a few percent of the bytes that travel.

It still belongs in a build. It will not fix a slow page though. Images cost the most on almost every site. The image compressor will do more for load time than any markup trick.

Never edit the minified version

Treat minification as a build step like you do for CSS and JavaScript. The formatted file is your source. The minified file is output.

Lost the source? The HTML formatter can rebuild a readable version. Comments removed during minification are gone for good though.

Why the tool leaves attribute values alone

A class list with double spaces looks messy. A quick tidy seems harmless. Some scripts read attribute values exactly as written. A data attribute may hold text that needs its spacing. So the tool trims space between attributes and never inside a value.

A safe HTML minifier workflow

  1. Keep the readable file as your source.
  2. Edit and review only that source file.
  3. Minify a copy before you upload it.
  4. Open the minified page and check the spacing.
  5. Compress images on the same page for a bigger win.

This order keeps your work safe. A team never loses edits to a build that overwrote them.

Common HTML minifier problems

A gap disappeared between two items

The items had no text between them. Add a real space or use CSS margins for the gap.

An old browser feature stopped working

Your page may rely on conditional comments. Turn on the option to keep comments and run it again.

The saving looks small

Your markup was already compact. Most of its size may sit in text or inline data.

Tips for a faster page

  • Compress and resize images before anything else.
  • Turn on gzip or brotli on your server.
  • Minify CSS and JavaScript along with HTML.
  • Remove scripts that no page needs.
  • Cache static files in the browser for repeat visits.

Who uses an HTML minifier?

Web developers shrink templates for production. Email designers trim newsletters that hit size limits. Bloggers clean exported pages. Agencies prepare landing pages for launch.

Your pages stay private

The tool runs in your browser. Unreleased pages and internal templates never leave your device. Need to shrink styles and scripts too? Try the CSS minifier and the JavaScript minifier.

Frequently asked questions

Can minifying HTML break my layout?

A careless tool can. Space between inline elements shows as a real space. This tool keeps one space wherever text runs meet.

How much smaller will my page get?

Usually 10 to 25 percent of the raw size. Far less of the transfer size once gzip runs because indents compress well.

What happens to my pre and textarea content?

The tool keeps it exactly with every space and line break. Users see that whitespace on the page.

Should I keep comments?

Only if your build or an old browser target needs them. Otherwise they ship to every visitor for no reason.

Is an HTML minifier worth it?

Yes as a build step. Images usually cost far more though. Compress them first for the biggest speed gain.

Does the tool upload my HTML?

No. Your browser does all the work. Your pages stay on your device.