Minify your HTML code instantly with our free HTML Minifier. This tool removes unnecessary whitespace, line breaks, and comments from your HTML files to reduce their size and speed up page loads. It is ideal for optimizing web pages and applications for production. Simply paste your HTML and get the minified version in seconds, with live before-and-after size statistics.
Minification strips characters that the browser ignores anyway — so the page renders identically but downloads and parses faster. It is different from gzip compression (which the web server applies on top), and the two stack for the smallest transfer size. To make minified markup readable again, use the HTML Beautifier.
Here is a small HTML document before and after minification. The structure and content are identical — only the whitespace and formatting are removed:
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html><!DOCTYPE html><html><head><title>Demo</title></head><body><p>Hello, world!</p></body></html>HTML minification removes characters a browser does not need in order to render a page: runs of whitespace between tags, line breaks, indentation, and HTML comments. Because browsers ignore these in most contexts, the visible result is unchanged — but the file is smaller, so it transfers over the network faster and parses more quickly. That improves load time and Core Web Vitals, which is why production builds of almost every framework run a minifier automatically.
Minification is not the same as gzip or Brotli compression. Minification shrinks the source text; the server then compresses the minified result further over the wire. Applying both gives the smallest payload. A safe minifier never removes characters that are significant: it preserves whitespace inside <pre> and <textarea> elements, and keeps content inside <script> and <style> blocks intact rather than mangling the JavaScript or CSS inside them.
One important caveat: minify static HTML, not framework templates that depend on braces. Templates for Angular, Vue, JSX, and JavaScript template-literal systems contain curly-brace expressions and interpolation markers that a naive minifier could collapse or break. Those are handled by the framework's own build step. For data payloads instead of markup, see the JSON Minifier, and to test markup live, use the HTML Tryit Editor.
<pre> and <textarea> must keep its spacing; a good minifier preserves it. If yours flattens it, switch to a safer minifier.