HTML Minifier & Beautifier
Free browser-based HTML minifier and beautifier. Strip comments, collapse whitespace, or re-indent your markup — instant, no upload, no signup.
- Runs in your browser
- Tool input is not uploaded to ZeroTool servers
- Free · No Sign-Up
Scan with WeChat to share this tool
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.
Worked Examples
Before minify
<!DOCTYPE html>
<html lang="en">
<head>
<!-- page metadata -->
<title>Hello</title>
</head>
<body>
<h1>Hello World</h1>
<p>Some <strong>bold</strong> text.</p>
</body>
</html>
After minify
<!doctype html><html lang="en"><head> <title>Hello</title> </head> <body> <h1>Hello World</h1> <p>Some <strong>bold</strong> text.</p> </body></html>
Status bar: Minified — 200 B → 150 B (−25.0%). The comment is gone and each run of indentation became one space. The spaces between tags stay because the tool keeps every whitespace-only text node as a single space: in <p>Hello <strong>world</strong>!</p> the space before <strong> is visible, and the tool does not try to decide which spaces are safe to drop. Build-time minifiers such as html-minifier-terser remove more with options like collapseWhitespace.
What Gets Minified
- Whitespace between tags (inter-tag whitespace) is collapsed.
- HTML comments are removed — except IE conditional comments (
<!--[if IE]>). - Boolean attribute values like
disabled=""are simplified todisabled. - Whitespace runs in text collapse to a single space. Whitespace-only text between tags becomes one space; it is not removed, because the parser cannot tell which of those spaces are visible.
- When a block element such as
<p>or<h1>contains only text, the leading and trailing whitespace of that text is removed. Inline elements such as<strong>,<a>or<span>keep one space at each edge, because that space is visible:<strong>Note: </strong>read this.stays as it is.
What Is Kept
- Content inside
<script>and<style>, copied exactly as written. - Whitespace inside
<pre>,<textarea>,<code>,<samp>and<kbd>: nothing is collapsed. The browser writes this content again, so a character reference can change form (<becomes<) and attributes of elements inside get double quotes; the displayed text stays the same, including a blank first line in<pre>or<textarea>, also when one sits inside another of these elements. One exception is in a<pre>(a carriage return, shown as a space): it is written as the character itself, and the next parse reads it as a line break. - Attribute values, including quoted whitespace and inline event handlers.
When to Minify Production HTML
Most modern build pipelines minify HTML as part of the bundler step (Vite, Webpack, Astro, Next.js). Use this tool when you need a one-off minify — pasting from a CMS export, comparing before/after sizes, or sanity-checking a hand-written template. Beautify is the daily driver: paste minified HTML from production, get a readable copy to debug or diff.
Limits
- Inline elements keep a collapsed space at their edges even where CSS would hide it, for example at the start of a line. The tool does not read your CSS, so it cannot tell when
displayorwhite-spacechanges how spaces render. - Only HTML whitespace (space, tab, line feed, form feed, carriage return) is collapsed. Non-breaking spaces are kept:
Price: 10 EURcomes out with the same three non-breaking spaces, written as the character U+00A0 instead of . The full-width space U+3000 is also kept. - In a fragment, content that the HTML parser moves out of
<body>is written back in its original order: a conditional comment such as<!--[if mso]>before the first element, and<title>,<meta>,<link>or<style>before the body content. Ordinary comments are removed wherever they are. - Inline JavaScript and CSS are copied as they are. They are not minified.
- The HTML is parsed by the browser's
DOMParser, so invalid markup comes out repaired (missing end tags added, stray tags dropped), and the doctype is written as<!doctype html>.
FAQ
Will this break my JavaScript or CSS inside <script> and <style> tags?
No. The content of <script> and <style> is copied exactly as written. Inside pre, textarea, code, samp and kbd, whitespace is not collapsed, but the browser writes the content again, so a character reference can change form (< becomes <, © becomes ©); the displayed text stays the same, except that in a pre (a carriage return, shown as a space) becomes a line break. Outside those elements, minification removes comments (except IE conditional comments) and collapses each run of whitespace to one space; a block element that contains only text also loses the space at the start and end of that text.
Does my HTML get uploaded anywhere?
No. The browser's DOMParser reads the HTML in this tab and JavaScript on the page writes the result; the markup is not sent to a server and is not saved in browser storage. The page analytics record only the tool name and mode, minify or beautify, after you commit an input edit, click Minify or Beautify, or change the indent and the operation succeeds. Live typing does not record usage, and repeating an unchanged result does not add an event. HTML is not included.
How much size reduction can I expect from minification?
It depends on how much indentation and how many comments the input has, and inline script and style are not touched. The worked example below goes from 200 to 150 bytes (25%). The exact savings (original size, output size, percent) appear in the status bar after each minify.
What does Beautify do differently from formatting in my editor?
Beautify re-parses and re-indents your HTML from scratch — useful for normalizing inconsistently formatted markup, expanding one-line minified HTML, or applying a consistent style across exported output from a CMS or template engine.
Does it preserve the HTML5 doctype, attribute values, and inline event handlers?
They are kept, with some rewriting. The doctype is written as <!doctype html>, so the public and system identifiers of an older doctype are dropped. Attribute values, including inline handlers such as onclick and onload, keep their values, but they are written in double quotes with & and " escaped, and an empty value becomes the bare attribute name (disabled="" is written as disabled). IE conditional comments are kept when other comments are stripped, including one placed before the first element of a fragment.