Skip to content

HTML Minifier

Minified HTML —
Original size (bytes)
—
Minified size (bytes)
—
Bytes saved
—
Size reduction
—
Comments removed
—

Paste your markup and the minifier removes comments, collapses runs of spaces and line breaks, and drops whitespace between tags. A 33-byte snippet with one comment and indented lines shrinks to 19 bytes, a 42.4% reduction. Content inside pre, textarea, script and style elements is left exactly as written.

About this tool

Hand-written templates carry indentation, blank lines and developer comments that browsers ignore but still download. Minifying strips that overhead before you inline markup in an email, embed it in a JavaScript string, or ship a static page. This minifier shows the minified HTML along with the original and final size in UTF-8 bytes, the bytes saved and how many comments were removed. Two checkboxes let you keep comments or keep a single space between tags when inline elements depend on it. Conditional comments for old Internet Explorer survive. One limit: inline scripts and styles pass through unchanged, so run them through a dedicated JavaScript or CSS minifier if they are large. Everything runs in your browser.

How to use it

  1. Add the markup

    Paste HTML into the box or open a .html or .txt file from your device.

  2. Choose what to strip

    Untick Remove HTML comments to keep them, or untick Remove whitespace between tags to keep one space where tags meet.

  3. Check the savings

    Original size, minified size, bytes saved and the percentage reduction update as you edit.

  4. Copy the output

    Use Copy result to take the minified HTML into your project.

Examples

A comment and loose spacing

HTML to minify
<p> Hi </p> <!– c –> <b>x</b>
Remove HTML comments
Yes
Remove whitespace between tags
Yes

Result Minified HTML: <p> Hi </p><b>x</b>
Original size (bytes): 33
Minified size (bytes): 19
Bytes saved: 14
Size reduction: 42.4%
Comments removed: 1

  1. Protected 0 pre, textarea, script or style block(s) from changes.
  2. Removed 1 comment(s); conditional comments are kept.
  3. Collapsed whitespace and removed gaps between tags, dropping 4 character(s).
  4. Size: 33 bytes → 19 bytes, a saving of 42.4%.

The comment goes, double spaces become one and the line breaks between the two tags disappear, cutting 33 bytes to 19.

Preformatted text kept intact

HTML to minify
<div> <pre>a b</pre> </div>
Remove HTML comments
Yes
Remove whitespace between tags
Yes

Result Minified HTML: <div><pre>a b</pre></div>
Original size (bytes): 30
Minified size (bytes): 26
Bytes saved: 4
Size reduction: 13.3%
Comments removed: 0

  1. Protected 1 pre, textarea, script or style block(s) from changes.
  2. Removed 0 comment(s); conditional comments are kept.
  3. Collapsed whitespace and removed gaps between tags, dropping 4 character(s).
  4. Size: 30 bytes → 26 bytes, a saving of 13.3%.

Spacing inside the pre element is meaningful, so it stays exactly as written while the indentation around it is removed.

How it is calculated

reduction % = (original bytes − minified bytes) ÷ original bytes × 100

original bytes
UTF-8 size of the pasted HTML
minified bytes
UTF-8 size after comments and surplus whitespace are removed

First, pre, textarea, script and style elements are set aside so their contents cannot change. Ordinary comments are then deleted, while conditional comments starting with [if are kept. Every run of spaces, tabs and line breaks becomes one space, and when the option is on, whitespace sitting between a closing angle bracket and the next tag is removed. The protected blocks are put back and both versions are measured in UTF-8 bytes, so accented letters and emoji count as the 2 to 4 bytes they really occupy.

When not to use it

  • Pages served through a build pipeline that already minifies HTML gain nothing from a second pass.
  • Markup whose layout relies on spaces between inline elements, such as inline-block buttons, may shift when gaps between tags are removed.

Common mistakes

  • Expecting inline JavaScript or CSS to shrink, when those blocks are deliberately left unchanged.
  • Editing the minified copy by hand instead of keeping the readable source and minifying again.
  • Removing gaps between tags in running text, which can join two words split across inline elements.

Frequently asked questions

Will minifying change how my page looks?

Usually not, because browsers already treat a run of whitespace as one space. The exception is whitespace between inline elements: removing it can close a visible gap between two links or inline-block boxes. Untick Remove whitespace between tags to keep a single space there.

Are conditional comments removed?

No. Comments that start with [if, used to target old versions of Internet Explorer, are kept because they carry markup. All other comments are removed when the comments option is ticked.

Why are script and style blocks left alone?

JavaScript and CSS have their own syntax, where collapsing a line break can change meaning, for example after a statement without a semicolon. Those blocks are passed through untouched; use a JavaScript or CSS minifier on them separately.

How much smaller will my HTML get?

It depends on how the source is written. Heavily indented templates with comments often shrink by 10 to 30 percent before compression. Once a server applies gzip or Brotli the transfer difference is smaller, since compression already handles repeated whitespace well.

Why is the byte count higher than the character count?

Sizes are measured in UTF-8, the encoding web pages use. Plain ASCII characters take one byte, but accented letters take two, most other scripts three, and emoji four.

Is my markup uploaded anywhere?

No. The minifying runs in your browser and the HTML is not sent to a server, so private templates and unpublished pages stay on your device.

Cite this tool

Using this tool in an assignment, article or report? Copy a citation, or a link for your website.

APA

Tools Directory Editorial Team. (2026, October 18). HTML Minifier. Tools Directory. Retrieved October 26, 2026, from https://tools.milunir.com/developer-tools/html-css-and-frontend/html-minifier/

MLA

Tools Directory Editorial Team. “HTML Minifier.” Tools Directory, 18 Oct. 2026, https://tools.milunir.com/developer-tools/html-css-and-frontend/html-minifier/. Accessed 26 Oct. 2026.

Chicago

Tools Directory Editorial Team. “HTML Minifier.” Tools Directory. Last modified October 18, 2026. Accessed October 26, 2026. https://tools.milunir.com/developer-tools/html-css-and-frontend/html-minifier/.

Link<a href="https://tools.milunir.com/developer-tools/html-css-and-frontend/html-minifier/">HTML Minifier – Tools Directory</a>