What is minification?
Code written for people is full of things browsers do not need: indentation, line breaks, comments and spaces around punctuation. Minification removes them, producing a smaller file that behaves exactly the same. Smaller files download faster, especially on mobile connections, which improves page speed and Core Web Vitals scores.
This minifier is deliberately conservative. It never renames variables or rewrites logic, so the output is safe to drop straight into a page. It understands strings, template literals and regular expressions in JavaScript, keeps /*! license */ comments, leaves <pre> and <textarea> content untouched in HTML, and minifies inline <style> and <script> blocks too.
How to use it
- Choose CSS, HTML or JavaScript. An example loads so you can see the result.
- Paste your own code into the left box.
- Copy or download the minified output. The size before and after is shown underneath.
What gets removed
| Language | Removed | Kept |
|---|---|---|
| CSS | Comments, line breaks, spaces around { } : ; , >, last semicolons | Strings, spaces inside calc(), descendant selectors |
| HTML | Comments, repeated whitespace, spaces next to block-level tags | pre, textarea, conditional comments, single spaces between inline elements |
| JavaScript | Comments, indentation, spaces around operators, safe line breaks | Names, strings, template literals, regular expressions and line breaks that automatic semicolon insertion relies on |
When to use a build tool instead
For production websites with a build step, tools such as esbuild, Terser or Lightning CSS go further: they rename local variables, remove unused code and bundle modules. Those tools typically shrink JavaScript by a further 20–40%. Use this minifier for quick jobs, snippets, email templates, CMS custom code fields and sites without a build process.
Also remember that servers compress text with gzip or Brotli. Minification and compression work together: minify first, then let the server compress.
More worked examples
Stylesheet: a 189-byte CSS snippet with comments and indentation shrinks to 137 bytes, a 27.5% saving, before server compression is applied.
Common mistakes to avoid
- Editing minified files. Keep the readable source and minify a copy.
- Skipping server compression. Minify and also enable gzip or Brotli on the server.
- Expecting full optimization. Build tools also rename variables and remove unused code. Format JSON with the JSON formatter.
Sources and methodology
The calculations on this page follow these published standards and references. The code is covered by automated tests against known values.