HTML Minifier
Minify HTML by removing unnecessary whitespace and comments for a smaller output.
This tool runs entirely in your browser. Your files are never uploaded to a server.
<main><h1>Hello</h1></main>What this minifier does
Compacts HTML by removing ordinary comments, deleting whitespace between tags, and reducing runs of two or more whitespace characters elsewhere to one space. Complete pre, textarea, script, and style blocks are preserved unchanged when the simple matcher recognizes them; conditional comments beginning with [if are retained.
How to use it
Paste markup, inspect the immediate output, and copy it when ready. Reset clears the editor; no file is downloaded.
Important limitations
This is a regular-expression transformation, not an HTML parser, validator, sanitizer, optimizer, or compressor. It does not remove optional tags or quotes, rewrite attributes, minify embedded CSS/JavaScript, repair markup, or report errors. Malformed raw-text blocks, templates, unusual comments, and whitespace-sensitive inline content can produce unexpected or changed rendering.
How whitespace collapsing works
Text between tags is scanned for runs of two or more whitespace characters, which collapse to a single space; whitespace sitting directly between two tags with nothing else between them is removed entirely rather than collapsed.
Example
Pasting `<div> <p>Hello</p> </div>` produces `<div><p>Hello</p></div>` on one line, with the whitespace between the tags removed entirely rather than shrunk to a single space.
Safe review workflow
Load the minified page in a real browser before deployment, checking inline elements next to visible text where a removed space between tags can visibly join two words together.
Safe workflow and privacy
Keep the source, compare sizes, and test the result in target browsers before deployment. Processing is local and pasted HTML is not uploaded.
Frequently Asked Questions
- What does the HTML Minifier do?
- Minify HTML by removing unnecessary whitespace and comments for a smaller output.
- Does this HTML tool change program behavior?
- It only changes layout or removable whitespace. Review minified output before production use when code relies on unusual syntax.
- Is my code uploaded?
- Processing is local and your code is never uploaded.
Related Tools
HTML Formatter
Format and indent HTML code into a clean, readable structure directly in your browser.
CSS Formatter
Format and indent CSS code into a clean, readable structure directly in your browser.
YAML Formatter
Format and prettify YAML documents instantly in your browser.
CSS Minifier
Minify CSS by removing unnecessary whitespace and comments for a smaller output.
HTML Entity Decoder
Decode HTML entities like & and < back into readable text.
HTML Entity Encode
Escape text to safe HTML entities instantly and for free.