HTML Minifier
Paste a page or a fragment and get a smaller version back: indentation and layout newlines gone, comments removed, the document itself unchanged. Useful for templates, email HTML, embedded snippets, and anywhere markup travels by copy and paste.
Careful with your text: whitespace in HTML is not all decoration — a space between two words inside a sentence is content. This minifier only removes whitespace where the block layout makes it inert, and everything runs in your browser: your markup never leaves the device.
License comments (<!--! …) and legacy conditional comments are always kept — they carry attribution or browser targeting.
Minified HTML
156 bytes → 111 bytes (−28.8%) · 1 comment removed
Embed this calculator on your website →
The formula
tokenize → collapse text runs → drop whitespace only at block boundaries
- Removed: comments (license and conditional comments stay), whitespace-only gaps between block elements, and the extra padding inside tag brackets — <a href="/x" class="y" > becomes <a href="/x" class="y">.
- Preserved exactly: the single spaces between words and inline elements (Hello world keeps its space), attribute values byte-for-byte, and the contents of pre, textarea, script, style, and title elements — whitespace there is meaning, not layout.
- Never done: no optional-tag omission, no attribute quote stripping, no reordering. Malformed input (an unterminated tag or script) is refused, not guessed at.
Worked example: <div> <p> Hello </p> <span> a </span> <span> b </span> </div> becomes <div><p>Hello</p><span> a </span> <span> b </span></div> — the paragraph's padding goes (it is a block), while every space inside the inline spans stays, because there the space is text.
How it works
Checked against an independent parser. The engine's test battery compares its output with Python's standard HTML parser: the tag-and-text structure of input and output must agree, and minifying twice must be a fixed point. Whitespace inside sentences is compared deliberately — it is the part careless minifiers eat.
Block vs inline is the whole game. Browsers collapse whitespace, but a gap between two inline elements renders as a space, while a gap between blocks renders as nothing. The minifier keeps a list of block elements and only drops whitespace where at least one side is a block boundary — the rule that keeps your text intact.
Examples
- An email template — shrink hand-written email HTML before pasting it into the sending tool.
- An embedded widget snippet — one line instead of forty, ready to paste into a page or a README.
- A static page on a tiny host — every indentation level you wrote for yourself, removed for your visitors.
Frequently asked questions
Is my HTML uploaded anywhere?
No. The minifier runs entirely in your browser — after the page loads it works with the network unplugged. Pasting private templates or unreleased pages is safe.
Will it change how my page looks?
The rules only remove whitespace that block layout makes invisible. Spaces between words and inline elements are kept exactly, and pre, textarea, script, style, and title contents are copied byte-for-byte. If your layout deliberately depends on whitespace between inline elements, those spaces are preserved — they are inline spacing, and this tool keeps them.
Why keep the spaces inside <span> a </span>?
Because inside inline content, whitespace is text: the rendered page shows “ a ” with its spaces, and collapsing them would change sentences. Only whitespace at block boundaries — where the browser renders nothing — is removed.
Why not remove optional closing tags like </p> for more savings?
Deliberately out of scope. Optional-tag omission interacts with parsing rules in ways that can silently change a document on malformed or unusual input. This minifier's promise is a smaller file with the same structure — conservative beats clever.
What happens to my scripts and styles?
Their contents pass through byte-exact — the engine never looks inside script or style elements. To shrink those, run the code through the CSS Minifier or a dedicated JavaScript tool first, then minify the page.
Related calculators
CSS Minifier
LiveShrink a stylesheet safely in your browser: comments and needless whitespace removed with conservative, structure-preserving rules — your code never leaves the device.
JSON Formatter & Validator
LiveFormat, validate, and minify JSON, with the exact position of any syntax error pointed out.
Slug Maker
LiveTurn a title or phrase into a clean URL slug — lowercased, hyphenated, and stripped of accents and punctuation.

