Code Minifier

Minify HTML, CSS, and JavaScript to reduce file size. See percentage saved instantly.

0 chars

A pattern-based minifier with separate HTML, CSS, and JS modes, plus a live percentage showing how much smaller the output is. It strips comments and collapses whitespace — it does not parse, rename variables, or tree-shake. That makes it right for email templates, snippets pasted into a CMS, and inline styles, and wrong as a replacement for terser or cssnano in a build pipeline.

What each mode removes

HTML mode deletes <!-- --> comments, collapses all whitespace runs to a single space, removes whitespace between adjacent tags, and tightens spaces around = signs. CSS mode strips /* */ comments, tightens whitespace around { } : ; , > ~ +, and drops the final semicolon before each closing brace. JS mode removes // and /* */ comments using a scanner that tracks string and template-literal boundaries — so the // in a URL string like "https://example.com" survives — then tightens whitespace around operators and punctuation.

Known hazards of regex minification — check these before shipping

Because nothing here builds a syntax tree, some transformations are unsafe. In CSS, calc() expressions using + break: calc(100% + 20px) becomes calc(100%+20px), which browsers reject (subtraction happens to survive because - is not in the tightened set). In JS, a + +b becomes a++b — a different program. Whitespace inside JS strings and template literals is collapsed, so "hello world" silently becomes "hello world". In HTML, <pre> and <textarea> content is collapsed like everything else, and the = tightening applies to visible text too: <p>Price = 5</p> becomes <p>Price=5</p>.

The practical rule: minify, then eyeball the diff or run the result once. For anything with calc(), significant whitespace, or dense operator chains, use a real parser-based minifier instead.

CSS mode
Input: /* card */ .card { margin: 0 auto; color: #333; } .card > p { padding: 4px; }
Output: .card{margin:0 auto;color:#333}.card>p{padding:4px}
83 characters in, 51 out — the tool reports this as 39% smaller.
JS mode changing semantics
Input: const c = a + +b;
Output: const c=a++b;
Unary plus fused into an increment — the output is a syntax error here, and in other arrangements it can be silently wrong code.
Good to know: Do not run JSON through JS mode — string contents get their internal whitespace collapsed. The JSON formatter's own Minify button is lossless because it re-serializes through a real parser.