HTML Minifier
Minify HTML by removing comments and whitespace in your browser. Free, online, no upload, fully private.
How to Use
- Paste or type your HTML code into the HTML Minifier input area above.
- Configure any format or mode options to generate the minified HTML in real time.
- Click Copy to copy the formatted result to your clipboard, or Reset to clear the workbench.
What is HTML Minifier?
An HTML Minifier compresses HTML markup by removing HTML comments and collapsing unnecessary whitespace between tags, reducing raw byte size for faster network delivery. Web developers use it to shrink static HTML partials, email markup, and embedded widget snippets.
How It Works
As you type or paste HTML, minify() runs a live pipeline: stripping <!-- ... --> comments, collapsing consecutive whitespace runs to a single space, trimming whitespace around < and >, removing gaps between adjacent tags (> < → ><), and trimming outer spaces. It immediately prints the compressed markup along with original-vs-minified character counts and percentage reduction.
Common Use Cases
- Reducing inline HTML widget payload size — strip comments and formatting whitespace before storing templates in JS
- Measuring compression savings immediately — view exact character count drops (before → after and % smaller) live
- Cleaning developer notes before publishing — remove HTML comments (<!-- ... -->) from markup automatically
- Preparing compact HTML snippets — copy minified single-line markup locally without installing build plugins
Technical Details
Pipeline: strips <!--...-->, collapses \s+ to " ", strips \s*([<>])\s*, collapses >\s+< to ><, and trims. Note: regex pass operates across full input (avoid whitespace-sensitive <pre> blocks). Live output with character-reduction stats locally.
FAQ
Is my HTML uploaded?
No. Minification happens locally in your browser. Your markup never leaves your device.
Are inline scripts and styles preserved?
Yes. Content inside script and style tags is preserved; only surrounding HTML whitespace and comments are removed.