What is HTML Minifier?
A HTML Minifier reformats your input for readability without changing its meaning. It parses the source, applies consistent indentation, spacing and casing, and returns a clean copy you can paste back into your project. Strip comments and collapse whitespace between tags.
HTML Minifier
Strip comments and collapse whitespace between tags - typical 20-40% size reduction.
TLDR
Paste HTML and click Run. The page strips HTML comments (), removes whitespace between tags, and collapses internal whitespace runs to single spaces. Typical savings: 20-40%.
How to use this tool
- Paste your HTML into the input box, or click Load sample to try it.
- Click Run. The tool strips comments, removes whitespace between tags, and collapses internal runs of whitespace to a single space.
- Read the savings. The status line shows the before and after byte counts and the percentage saved.
- Click Copy output to put the minified HTML on your clipboard, then paste it into your file or build.
- Nothing is stored. The transform runs on your device; close the tab and both input and output are gone.
What HTML minification removes
Minification shrinks a file by deleting bytes a browser ignores, without changing how the page renders. The three transforms this tool applies cover the bulk of the savings on typical hand-written markup.
| Transform | Before | After |
|---|---|---|
| Strip comments | <!-- nav --><ul> | <ul> |
| Whitespace between tags | </li> <li> | </li><li> |
| Collapse whitespace runs | Hello world | Hello world |
Gzip or Brotli compression on the server then squeezes the result further, so minified HTML that looks only 25 percent smaller as plain text can shrink dramatically more once compressed and sent over the wire.
Worked example
Take a small, comment-laden snippet and trace what each pass does.
- Input: an HTML block with a leading comment, indented tags, and double spaces inside a paragraph, about 120 characters.
- Strip comments: the comment line vanishes, removing the marker and its text.
- Remove inter-tag whitespace: the newlines and indentation between tags disappear, so the tags sit flush against each other.
- Collapse whitespace: the double space inside the paragraph becomes a single space, preserving the visible text.
- Output: roughly 75 characters, a saving near 35 percent, with identical rendering in the browser.
About this tool + how it works
This tool runs 100% in your browser - the libraries load from a public CDN and the math runs on your device. Nothing is uploaded to a server. The underlying logic is:
remove , replace >\s+< with ><, collapse \s+ to ' '
You can verify by opening the browser developer tools and watching the Network tab; you'll see no requests fired during normal use beyond the initial page and library load.
Real-world scenarios where this tool helps
Quick inspection
You got a blob of HTML from a third-party site - paste, run, read.
Bug hunting
Reformat minified HTML so you can step through it in DevTools or follow the logic.
Sharing code
Paste from chat, get clean HTML you can drop straight into a file.
Pre-commit cleanup
Run a quick format on a snippet before pasting into a PR or wiki.
What this tool does
- Performs the html minifier entirely in your browser - no upload, no API call.
- Loads the formatting / minifying library from a public CDN; library is cached after first use.
- Shows before / after byte count and a savings percentage.
- One-click Copy output and Load sample buttons.
- Works on phones, tablets, and desktops; loads in under a second.
What it does NOT do
- Does not store, log, or send your input anywhere.
- Does not require an account, an API key, or a paid plan.
- Does not validate or compile the code beyond what the formatter checks - syntax errors may produce unhelpful output.
- Does not preserve comments perfectly in every minifier (some minifiers strip them entirely).
Common mistakes and pitfalls
- Pasting code that depends on whitespace (Python, YAML) into a tool that collapses whitespace - that will break.
- Expecting a minifier to make broken code work - bad input gives bad output.
- Comparing the result to a paid tool that has extra optimization passes - this tool does the standard pass.
- Forgetting to click Copy output before navigating away - the output lives only in the page.
Frequently asked questions
Is this html minifier free?
Yes - free forever, no signup, no daily limit. Everything runs in your browser.
Where does my code go?
Nowhere. The transform runs entirely in your browser. Nothing is uploaded, stored, or logged.
Does it work offline?
After first load, yes. The CDN-loaded libraries cache in your browser and the page works without a connection.
Is the output exactly the same as my IDE?
Very close - the library is the same one most IDEs use under the hood (js-beautify for HTML/CSS/JS; Terser for JS minification; js-yaml for YAML). Spacing and line-break choices may differ by a few characters versus Prettier.
Will it handle very large files?
Yes up to several megabytes. For 10+ MB inputs the browser may freeze briefly during processing.
Will the minified output break in older browsers?
Minifiers do not introduce new syntax - they just shorten what is already there. If the input ran on Internet Explorer 11, the minified version still does. For modern ES2022+ syntax check your Babel/SWC config separately.
Does the formatter / minifier preserve comments?
Formatter: yes by default. Minifier: depends. Terser drops all comments unless they look like /*! ... */ legal headers. CSS / HTML minifiers strip all comments unless preceded by `!`.
Can I run this on a whole codebase?
Not in one click - this tool processes one file at a time. For a whole codebase use prettier --write . / eslint --fix / terser --compress in your CI. This tool is for quick one-off paste-and-format.
Is the source map preserved when minifying?
No - the tool minifies in place and returns just the minified code. For production builds that need source maps, run Terser in your bundler (Webpack/Vite/esbuild) where the source-map pipeline is wired in.
How does this compare to Prettier?
Prettier is opinionated and reformats more aggressively (line length, trailing commas, quote style). js-beautify is conservative - it preserves most stylistic choices and just fixes indentation + whitespace. Use Prettier for team-wide style consistency; use this for ad-hoc inspection.
