HTML Minifier
This HTML minifier removes comments and collapses the whitespace between tags, and stops there. The approach is deliberately conservative: aggressive minifiers also drop optional closing tags and unquote attribute values, which is valid HTML but changes how some parsers and email clients behave. Content inside pre, textarea, script and style is lifted out and put back untouched, because whitespace there is either rendered or is not markup at all, and conditional comments are kept because some mail clients still act on them. The saving is reported as you go.
How it works
Removes comments and collapses the whitespace between tags. The approach is deliberately conservative: the goal is to remove what is provably ignorable, not to squeeze out the last byte at the risk of changing how the page renders.
Content inside <pre>, <textarea>, <script> and <style> is lifted out and put back untouched, because whitespace there is either rendered or is not markup at all. Conditional comments are kept, since some mail clients still act on them.
Everything runs in your browser — nothing you paste is sent to a server.
How to minify HTML
- Paste your markup into the input on the left.
- Choose whether to strip comments.
- Copy or download the minified result, with the saving shown below.
Conservative on purpose
The aim is to remove what is provably ignorable, not to squeeze out the last byte. Aggressive minifiers drop optional closing tags and unquote attribute values, which is valid HTML but changes how some parsers and email clients behave. This removes comments and the whitespace between tags, and stops there.
What is protected
<pre>and<textarea>, where whitespace is rendered.<script>and<style>, whose contents are not markup at all.- Conditional comments, which some mail clients still act on.
Common use cases
- Shrinking an email template, where every kilobyte counts against clipping limits.
- Reducing a page you are inlining into another document.
- Cutting the size of markup stored in a database column.
Frequently asked questions
Will minifying break my page?
It should not. Only comments and the whitespace between tags are removed, and the elements where whitespace is meaningful are protected, so the rendered result is the same.
Why not remove optional closing tags too?
Because it is valid HTML that some parsers and email clients handle differently. The extra saving is small and the risk is not, so this minifier stops short of it.
What is protected from minification?
Content inside pre and textarea, where whitespace is rendered; script and style bodies, which are not markup; and conditional comments, which some mail clients still act on.
How much smaller does HTML get?
Typically 10 to 30 percent for indented markup, depending on how much of it is nesting and comments. The exact saving is shown under the output.
Is my code uploaded anywhere?
No. Everything runs entirely in your browser, so nothing you paste is transmitted or stored on a server.
Related tools
HTML Formatter & Beautifier
This HTML formatter re-indents markup using a real parser, so nesting and inline elements are handled correctly.
CSS Minifier
This CSS minifier strips comments and whitespace while protecting strings and url() values.
HTML Viewer & Live Preview
This HTML viewer renders your markup as you type, inside a sandbox that cannot run scripts.