Skip to content

HTML minifier

Shrink HTML by stripping comments, extra whitespace and empty attributes.

Input
Output

HTML minifier

Paste any HTML document or fragment and this tool returns a smaller version with the same rendered result. It strips comments, collapses redundant whitespace between tags and inside attribute lists, and removes empty attributes such as class="" that a browser ignores anyway. Use it before shipping a static page, embedding a template into another system, or pasting markup somewhere with a size limit.

Four options control how far the minification goes. "Preserve pre, textarea and script content" keeps the exact whitespace inside those elements untouched by default, since a stray space inside a <pre> block or a script is often meaningful; turn it off only if you know that content can tolerate whitespace collapsing. "Merge multiple spaces in text" turns runs of spaces, tabs and line breaks inside ordinary text into a single space. "Remove quotes from simple attribute values" drops the quotes around values like id=box that don't need them under the HTML5 spec — anything with a space, an equals sign or another quote stays quoted. "Remove optional closing tags" drops closing tags a browser infers on its own, like the </li> before another <li> or the </td> before </tr>, using the same rules browsers use to auto-close them.

The tool works on the raw text of your markup rather than re-serializing a full DOM, so it never rewrites tag or attribute name casing — inline SVG with case-sensitive elements like viewBox or clipPath comes through unchanged. It handles both Windows and Unix line endings, and the tally under the output reports the byte size before and after minification along with the percentage saved.

Everything runs locally in your browser — your markup is never uploaded anywhere, which makes this safe for internal templates or anything not yet public. Copy the result, download it as a .txt file, or send the output back into the input to layer another pass.

FAQ

Will this break my page?
The default options are conservative: pre, textarea and script content is left untouched, and closing tags are only removed where the HTML5 spec says a browser infers them anyway. Review the result before publishing if you turn on the more aggressive options.
Does it minify the CSS and JavaScript inside my HTML?
No. Content inside <style> tags is treated as ordinary text and content inside <script> tags is preserved by default. Use a dedicated CSS or JS minifier on that code separately, then paste the combined page here.
What happens to comments?
All HTML comments are removed, including ones used for notes or section markers. If you need to keep a specific comment, remove it from the input before pasting, or reinsert it after minifying.
Why does an empty alt attribute stay on my images?
alt="" is meaningful — it tells assistive technology an image is decorative — so this tool keeps it even though it removes other empty attributes like class="".
Is my HTML uploaded anywhere?
No. Minification runs entirely in your browser using local JavaScript — your markup never leaves your device.