HTML Minifier
Compress your HTML by removing whitespace, comments, and empty lines
Reduce the size of your HTML file
Indentation, blank lines and developer comments make source code pleasant to edit but add bytes that browsers never need. This minifier removes that overhead from pasted HTML and reports how much smaller the result is. It is a lightweight text-based squeeze: it does not rewrite your markup, rename anything or touch the logic of embedded code.
How to minify a document
- Paste your markup into the Source HTML editor. Load Sample inserts a short header-and-article example with a comment, useful for a first try.
- Look at the two checkboxes under the editor. Remove Comments and Collapse Whitespace are both ticked by default; untick either one to skip that step.
- Press Minify HTML Now.
- Read the header numbers: Original, Minified and Savings. Sizes are calculated in bytes and displayed as B, KB or MB, and the original size updates while you type.
- Take the result from Minified HTML Output using Copy or Download, which produces minified.html.
What each option changes
- Remove Comments deletes everything between the comment opening and closing markers, across multiple lines.
- Collapse Whitespace turns every run of spaces, tabs and line breaks into a single space, and then removes whitespace sitting directly between a closing bracket and the next opening bracket.
Nothing else is altered: attribute quotes, optional closing tags and inline CSS or JavaScript are left as they are.
When it is worth using
- Trimming a static landing page or an HTML email body before uploading it.
- Preparing a template string that will be embedded in a JavaScript file or a JSON payload on one line.
- Estimating how much whitespace a hand-written page carries before you decide on a build step.
- Making a long snippet short enough to paste into a form field with a character limit.
Watch out for these cases
Collapsing whitespace is applied to the whole text, so content inside pre or textarea will lose its line breaks and spacing. A line comment inside an inline script, written with two slashes, can swallow the code after it once line breaks are gone, so either keep Collapse Whitespace off for such pages or convert the comment first. Conditional comments used for old Internet Explorer versions are also removed when Remove Comments is on. Because it works on plain text with simple pattern matching, always load the minified page in a browser and check it before publishing. The percentage saved varies with how much indentation the original had.
Related Tools