HTML Minifier

Remove HTML comments and redundant whitespace safely.

  • Runs locally in your browser
  • No upload required

Try it

Paste HTML. Raw script/style/pre/textarea content is preserved.

Minified HTML
<div><p>Hello</p></div>
Size
42 → 23 characters (19 saved)

Supported formats

Input
text, boolean
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Reduced 42 to 23 characters of HTML.

How it works

  • Removed comments, keeping conditional comments.
  • Collapsed whitespace between tags to a single space where it is meaningful.
  • Preserved script, style, pre and textarea bodies verbatim.
  • Inter-tag whitespace is collapsed, not blindly deleted, so inline spacing is usually preserved.
  • Minifying the result again changes nothing.

Methodology

  1. Tokenise the markup into tags, comments, raw bodies and text.
  2. Remove comments unless disabled, keeping conditional comments.
  3. Collapse whitespace in text and inside tags; copy raw bodies verbatim.

Usage

  1. Paste or type an HTML document.
  2. Choose whether to remove comments.
  3. Run the minifier and copy the smaller markup.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Comments and whitespace removed

jsonSelect to copy
{
  "text": "<div>\n  <p>Hello</p>  <!-- note -->\n</div>",
  "removeComments": true
}

Comments kept

jsonSelect to copy
{
  "text": "<div><!-- keep me --></div>",
  "removeComments": false
}

Script body preserved

jsonSelect to copy
{
  "text": "<script>  var a = 1;  </script>",
  "removeComments": true
}

Limitations

Safe minification

Minification is only useful if it is safe. This minifier treats comments, raw bodies and quoted attribute values as protected, and collapses rather than deletes inter-tag whitespace.

Frequently asked questions

Is my JavaScript or CSS inside the page touched?
No. script, style, pre and textarea bodies are copied byte-for-byte.
Will minifying break my inline spacing?
Whitespace between tags is collapsed to a single space rather than removed, so most inline spacing is preserved; complex mixed-inline layouts should be checked.
Is my HTML uploaded?
No. The document is processed entirely in your browser.

Sources

  1. HTML Living Standard — WHATWG
  2. MDN Web Docs — HTML elements reference — MDN