HTML Minifier
Remove HTML comments and redundant whitespace safely.
- Runs locally in your browser
- No upload required
Try it
Supported formats
Privacy
Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.
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
- Tokenise the markup into tags, comments, raw bodies and text.
- Remove comments unless disabled, keeping conditional comments.
- Collapse whitespace in text and inside tags; copy raw bodies verbatim.
Usage
- Paste or type an HTML document.
- Choose whether to remove comments.
- 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
{
"text": "<div>\n <p>Hello</p> <!-- note -->\n</div>",
"removeComments": true
}Comments kept
{
"text": "<div><!-- keep me --></div>",
"removeComments": false
}Script body preserved
{
"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
- HTML Living Standard — WHATWG
- MDN Web Docs — HTML elements reference — MDN
Send feedback
Tell us if this tool helped, report a problem, or suggest a tool. Only the message you type is sent — never the input you used in the tool.
Was this tool useful?
Prefer to write to us directly? See the contact page.