My Tool Studio
Developer

HTML Minifier

This HTML minifier shrinks markup by removing comments and collapsing whitespace, and it can minify the CSS and JavaScript inside the page in the same pass. Style blocks and style attributes go through the CSS minifier, script blocks through Terser, and JSON-LD is compacted. Optional steps shorten boolean attributes such as disabled="disabled", drop redundant type attributes and empty class or style attributes, and remove quotes around simple attribute values. The spaces that matter stay: the space between words and inline tags like strong is kept, and pre, code and textarea content is left as written. Upload an .html file or paste code, see the bytes before and after with a gzip estimate, and download the .min.html file.

Always freeNo sign upRuns in your browser
Output appears here...

How to use

01

Paste or upload your HTML

Drop a page, template or snippet into the Input pane, or click Upload .html. Try sample loads a page with a comment, a style block, JSON-LD, a script and extra spaces.

02

Pick options and click Minify

Tick the steps you want, from Remove comments to Remove attribute quotes where safe. Click Minify, or turn on Live mode. The line under the panes shows the size before and after, the percent saved and a gzip estimate.

03

Copy or download the result

Click Copy, or Download to save a .min.html file. If a script cannot be parsed, a notice says so and that script is left unchanged. Beautify instead reformats the input when you need to read it.

Why HTML Minifier

What the HTML minifier removes and keeps

The goal is output that renders the same as the input, which rules out some aggressive tricks and explains why a few spaces survive.

Here is a worked example with the sample page. The comment disappears, the head and body tags sit next to each other, Order #1042 becomes Order #1042, and the space before the strong tag in the paragraph is kept. With the default options, the style block becomes h1{color:#333;margin:0}, the JSON-LD block becomes one line, the greet function is shortened by Terser, and the pre block keeps its spacing.

ContentWhat happens
CommentsRemoved (untick Remove comments to keep them)
Conditional comments starting with [ifKept
Runs of spaces, tabs and line breaksCollapsed to one space
Whitespace next to block tags (div, p, li, table, h1 to h6 and similar)Removed
The space between text and inline tags (a, strong, span, img)Kept as one space
pre, code and textarea contentLeft exactly as written
style blocks and style attributesMinified with Minify inline CSS
script blocks and JSON-LDMinified with Minify inline JavaScript and JSON-LD; other script types kept
Boolean attributes, type attributes, empty attributes, quotesChanged only when you tick those options
Optional closing tagsLeft in place

Common questions

Will minifying HTML break my page layout?
It should not with this tool. Whitespace is only removed next to block-level tags, where browsers ignore it, and one space is kept between inline elements. Pages that use CSS white-space: pre on elements other than pre and textarea can change, so check those after minifying.
Does minified HTML improve page speed and Core Web Vitals?
A little. Smaller HTML downloads sooner, so the browser can start parsing and loading resources earlier, which can help Largest Contentful Paint on slow connections. The gain is usually small next to images, fonts and scripts, so treat it as a finishing step.
Should I minify HTML if my server already uses gzip or Brotli?
It still helps, but less. Compression already squeezes repeated whitespace, so the transfer saving is smaller than the raw byte saving. The gzip estimate under the panes shows the compressed size of the minified output. Minifying also removes comments you may not want to publish.
Can I minify inline CSS and JavaScript at the same time?
Yes. With Minify inline CSS ticked, style blocks and style attributes are minified, and with Minify inline JavaScript and JSON-LD ticked, script blocks go through Terser and JSON-LD is written on one line. Scripts with another type, such as a template, are left alone, and a script that fails to parse stays as written.
Can minified HTML be turned back into readable code?
Yes. Click Beautify instead on this page, or paste it into the HTML Beautifier, which has more layout options. Comments removed by the minifier cannot be recovered, so keep your source file.
Is it safe to minify pages with inline JSON-LD or template tags?
JSON-LD is parsed and written back on one line, so its data does not change, and invalid JSON is left as is with a warning. Template syntax such as {{ name }} or {% if %} is treated as text, and runs of spaces inside it collapse to one, which most template engines accept. Test pages where whitespace inside template tags matters.
Does the HTML minifier remove conditional comments for Outlook and old IE?
No. Comments that start with [if, used by old Internet Explorer and by many HTML email templates for Outlook, are kept. All other comments are removed.
How much smaller does HTML get after minifying?
It depends on how much indentation, how many comments and how much inline code the source has. Pages with large inline scripts and styles gain the most from the CSS and JavaScript options. The size line under the panes shows the exact saving for your input.
What does this HTML minifier leave alone?
It does not remove optional closing tags or default attribute values, and it does not rename classes or IDs. Attribute quotes are only removed when you tick that option, and only around values with no spaces or special characters. Those limits keep the output working with templates, CSS selectors and scripts that read your markup.

More Developer tools

View all