Minify HTML online for free with this HTML minifier. The tool removes whitespace, line breaks, and comments from your markup to reduce file size and speed up page loads — ideal for production websites, email templates, and cached fragments. Paste your HTML and get the minified version in seconds, with live before-and-after size statistics showing exactly how many bytes you saved.
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.
HTML compression is one of the simplest Core Web Vitals wins available. Every kilobyte of whitespace, indentation, and comment you strip from a document is a kilobyte the browser no longer has to download, parse, or hold in memory — which directly improves First Contentful Paint and Time to Interactive on slow connections and mobile devices. A reliable minify HTML online tool makes this a one-click step in any build pipeline.
Unlike gzipping, which happens at the server and is invisible to the source, minification produces a smaller file on disk that also speeds up caches, CDNs, and email clients that do not decompress consistently. Combined with CSS and JS minification, HTML minification routinely cuts total page weight by 10–20% before any server-side compression is applied. Everything runs locally in your browser, so even proprietary markup never leaves your device.
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>, <code>, and <textarea> elements must retain exact whitespace and line breaks. A robust minifier preserves these blocks verbatim. <script> or <style> blocks. Minify complex scripts separately using dedicated JS and CSS optimizers. Minification provides immediate payload reductions that compound when paired with modern HTTP transfer encoding (Gzip and Brotli). The following benchmarks illustrate typical savings across production web page archetypes:
| Page Archetype | Raw Unminified | Minified HTML | Minified + Gzip | Minified + Brotli | Net Bandwidth Reduction |
|---|---|---|---|---|---|
| SaaS Marketing Landing Page | 148 KB | 112 KB (-24.3%) | 28.4 KB | 22.8 KB | 84.6% |
| Long-Form Editorial / Blog Article | 86 KB | 68 KB (-20.9%) | 19.2 KB | 15.6 KB | 81.9% |
| E-Commerce Product Listing | 312 KB | 226 KB (-27.5%) | 46.5 KB | 37.1 KB | 88.1% |
| Single Page App Shell (SPA Index) | 34 KB | 24 KB (-29.4%) | 7.2 KB | 5.9 KB | 82.6% |
Integrate automated HTML minification into your continuous delivery pipelines, static site generators, and serverless edge functions:
import { minify } from 'html-minifier-terser';
async function compressHtml(rawHtml) {
const minified = await minify(rawHtml, {
collapseWhitespace: true,
removeComments: true,
minifyCSS: true,
minifyJS: true,
removeRedundantAttributes: true,
useShortDoctype: true
});
return minified;
}import htmlmin
def compress_html(raw_html: str) -> str:
return htmlmin.minify(
raw_html,
remove_comments=True,
remove_empty_space=True,
keep_pre=True
)