HTML Minifier Online
Minify HTML by removing comments, collapsing whitespace, and stripping empty attributes.
When an HTML minifier is the right tool
HTML copies from editors often carry comments, extra spaces, and empty attributes that you do not want in a compact paste. This page is for that cleanup. The output updates as you type. You can turn each of the three steps on or off, and the output header shows approximate input and output size in kilobytes plus a savings percentage when the result is smaller.
This is a text rewrite, not a browser parser. If you also need an indented copy, use the HTML Formatter. To compare two versions, use HTML Diff.
Use cases
Shrinking a template or a static page
Load Sample pastes a short complete page with comments, an empty id="", and extra spaces in the title and a heading. With the default options, comments go away, the empty id is removed, and the markup is packed onto fewer lines. Check the savings figure if you care about the size change.
Keeping comments or spacing on purpose
Uncheck Remove Comments when you need to keep a note, or uncheck Collapse Whitespace when a pre or script block must stay formatted. Conditional comments that start with <!--[if are already left in place even when comment removal is on.
Stripping leftover empty attributes
Editors sometimes emit id="" or class="". The third checkbox removes those five attribute names when the value is empty and double-quoted. It will not touch a single-quoted empty value.
How minification works
If the input is empty or only whitespace, the output is cleared. Otherwise the three options run in order: comments, whitespace, empty attributes. Sizes are the UTF-8 byte length of the current input and output (via a Blob). A savings badge appears only when that percentage is greater than zero. Copy is available when there is output.
<header class="site-header" id="">
<!-- Main content -->
<h1> Hello, World! </h1>
</header>
<header class="site-header"><h1> Hello, World! </h1></header>The heading still has a single leading and trailing space, because runs of two or more spaces are collapsed rather than stripped around text. The empty id is gone; class="site-header" stays.
What this tool does not do
It does not parse HTML, minify CSS or JavaScript inside tags, or preserve whitespace in pre, script, style, or textarea when collapsing is on. It does not rewrite other empty attributes. Nothing is sent to a server. To turn the same markup into Markdown, use HTML to Markdown.
How to use HTML Minifier
- Paste your HTML, or use Load Sample to try a short page.
- Toggle Remove Comments, Collapse Whitespace, and Remove Empty Attributes as needed. The output updates as you type.
- Copy the result when it looks right, or Clear to start over.
Frequently asked questions
How is this different from Minify on the HTML Formatter page?
This page is a dedicated minifier with three optional steps, a live size display in KB, and a savings percentage. The HTML Formatter’s Minify mode always strips comments and collapses whitespace, has no empty-attribute option, and does not show sizes. Use this page when you want those checkboxes; use the formatter when you also need a beautified copy.
What does each checkbox do?
Remove Comments deletes <!-- … --> blocks, but leaves conditional comments that start with <!--[if. Collapse Whitespace turns whitespace between tags into nothing, then collapses runs of two or more spaces or line breaks inside text to a single space, and trims the result. Remove Empty Attributes drops class, id, style, title, or alt when the value is an empty double-quoted string (class="" or id=""). All three options are on by default.
Will whitespace inside pre, script, or style be kept?
Not if Collapse Whitespace is on. Those elements are not special-cased. Several spaces or line breaks inside a <pre> or a <script> are reduced to a single space, which can break formatted code or preformatted text. Turn that option off when those regions matter.
Which empty attributes are removed?
Only class, id, style, title, and alt, and only when they are written with empty double quotes. A single-quoted class='' is left alone, and empty attributes with other names are left alone. Values that contain a space are not treated as empty.
Is my HTML sent to a server?
No. Minification runs in your browser as you type. Closing the tab discards what you pasted. Do not paste pages that contain secrets or private user data if you would not be comfortable with them sitting in memory on this device.
Is there a file size limit?
There is no server-imposed limit, because nothing is uploaded. A few thousand lines is comfortable. A large exported page can make the tab feel slow; in that case, minify a smaller fragment or use a local tool.
Related tools and guides
References
- The HTML Living Standard describes how browsers parse markup and which elements preserve whitespace. This page is a set of regular-expression rewrites, not that parser, and it does not special-case
preorscript. - Production minifiers often parse HTML and offer safer handling of scripts and preformatted blocks. Use one of those when the options here would change meaning.