Good to know
What gets removed
- CSS: comments, line breaks and spaces around
{ } ; : , > ~, and the last semicolon before}. Text inside quotes is left alone. - JavaScript: comments and spacing between tokens. Strings, template literals and regular expressions are copied exactly. A line break is kept where removing it could change how the code runs, because JavaScript inserts semicolons automatically at some line ends.
- HTML: comments and runs of whitespace. Spaces between inline elements shrink to one space rather than vanishing, so words do not run together. The contents of
<pre>and<textarea>and quoted attribute values stay exactly as written. Conditional comments are kept. JSON in a<script type="application/json">or JSON-LD block is compacted.
Comments that start with /*! are kept in CSS and JavaScript, the usual way to protect licence notices.
A worked example
The sample stylesheet in the input box is 146 bytes:
/* Card styles */
.card {
padding: 24px;
border-radius: 12px;
box-shadow: 0 4px 16px rgb(0 0 0 / 10%);
}
.card > h3 {
margin: 0 0 8px;
}Minified, it becomes 101 bytes, about 31% smaller:
.card{padding:24px;border-radius:12px;box-shadow:0 4px 16px rgb(0 0 0 / 10%)}.card>h3{margin:0 0 8px}The saving is worked out as (1 − minified ÷ original) × 100, using UTF-8 byte sizes.
How it compares with build tools
Tools such as Terser, esbuild and cssnano go further: they shorten variable names, drop unused code and merge rules, often saving much more. This tool trades that extra saving for predictability, which suits a quick fix, a single file or a site without a build step.
Minify and compress
Minifying and server compression work together. Gzip or Brotli compression on your web server usually shrinks text files far more than minifying alone, and minified files compress slightly better still. Turn both on where you can.
Limits
The JavaScript minifier reads code token by token rather than fully parsing it, so unusual syntax can trip it. Always load the minified file in a browser and check the console before you publish it.