HTML Minifier
Shrink HTML for production instantly
Original HTML
Options
Minified HTML
Overview
The HTML Minifier strips comments, collapses whitespace between tags, removes optional structural wrapper tags, and minifies inline CSS/JS to shrink your markup for production — smaller downloads, faster parsing. Paste readable HTML and get compact output instantly, with a live before/after size comparison.
What This Minifier Controls
- •Whitespace collapse: multiple spaces and line breaks reduced to a single space, and whitespace between tags removed entirely
- •Comment removal: strip HTML comments (<!-- -->) from the markup
- •Structural wrapper tag removal: strip <html>, <head>, and <body> tags, which browsers imply automatically
- •Inline CSS minification: strip comments and collapse whitespace inside <style> blocks
- •Inline JS minification: strip // and /* */ comments and collapse whitespace inside <script> blocks
- •Size comparison: see original size, minified size, and percentage reduction side by side
When You’d Minify HTML
- •Shrinking a static page before deploying it to production to reduce payload size and improve load time
- •Minifying an email template or landing page where every byte of HTML counts
- •Cleaning up production output from a static site generator or server-rendered framework before serving it
- •Producing compact HTML for embedding inline in a JS template literal or a CMS content field
- •Comparing before/after byte counts to check the payload savings of a page for a performance audit
How to Minify HTML
- 1.Paste your HTML into the input editor, or upload a .html/.htm file
- 2.Choose which minification options to apply: comments, whitespace collapse, wrapper tags, inline CSS/JS
- 3.Minified output and the size-reduction percentage appear automatically
- 4.Copy the output or download it as a .html file
- 5.Check the before/after byte count to confirm the size savings before deploying
Edge Cases Worth Knowing
- •Removing <html>, <head>, and <body> tags is safe in most browsers since they are implied automatically, but only strip them if you control the full delivery pipeline — some strict parsers or server-side processing steps may expect them present
- •Collapsing whitespace between inline elements (e.g. two adjacent <span> tags) can change rendered spacing, since a space between inline elements is visually significant — check the rendered output if your layout depends on that whitespace
- •Inline CSS/JS minification is regex-based text minification, not a full parser — it will not catch CSS/JS syntax errors and does not rename variables or shorten selectors
Limitations
- •This is whitespace/comment/wrapper-tag minification, not full HTML compression — there is no attribute-value shortening, redundant-attribute removal, or image/asset optimization
- •Inline CSS/JS minification is intentionally conservative — for maximum compression (selector shortening, dead-code elimination, minified variable names), use a dedicated tool like cssnano or Terser on your CSS/JS source files directly
- •Very large HTML files may be slow to minify entirely in the browser — for production build pipelines, integrate HTML minification into your build tool (e.g. html-minifier-terser) instead of a one-off browser tool
Need to Go the Other Way?
If you have minified or poorly indented HTML and need to make it readable for debugging or review, use the HTML Beautifier instead. It reformats markup with proper indentation based on tag nesting and validates tag structure as you type.