HTML, CSS & JavaScript Minifier — beautify and minify online
Minify or beautify HTML, CSS, and JavaScript in your browser. Tag-aware HTML, comment-stripping CSS, JSMin-safe JS — nothing is uploaded, no signup, sources cited below.
How it works
Each language gets a small, character-by-character state machine rather than a global regex pass. This matters because the three things that trip up naive minifiers — a `//` inside an HTML attribute or a CSS url(), a `:` inside a CSS string, a `/` that opens a JavaScript regex literal — all need surrounding context to be read correctly.
The HTML pass follows the same tag-vs-text tokenization the WHATWG parser uses. Standard <!-- ... --> comments are stripped; conditional comments (<!--[if IE]>…) and bang-prefixed comments are kept. Runs of whitespace inside text nodes collapse to a single space; whitespace flanking a tag boundary is dropped entirely. Anything inside <pre>, <textarea>, <script>, <style>, <code>, <svg>, or <math> is copied through byte-for-byte — those bodies are governed by another grammar.
The CSS pass follows CSS Syntax Module Level 3. The tokenizer recognises strings (single- and double-quoted) so a colon or comma inside one is never touched. Comments are stripped, except /*! … */ bangs — the convention every minifier respects for licence banners. Whitespace runs collapse, and the space adjacent to { } ; , : > ~ + is dropped. The last ; before a closing } goes too — it is optional by the spec.
The JavaScript passis Douglas Crockford's JSMin algorithm, lifted into TypeScript and extended to recognise ES2024 syntax: template literals (with ${expr} brace tracking), regex literals (disambiguated from division by inspecting the previous token), and Unicode identifiers. Whitespace is removed except where deleting it would either join two identifier characters (e.g. return foo must keep its space) or change semantics under automatic semicolon insertion. A bare return followed by a newline is preserved because ASI would otherwise insert a semicolon — collapsing the newline to a space changes what the function returns. Identifiers are never renamed and dead code is not removed, so stack traces and source maps remain meaningful.
Every successful run is cross-checked with an idempotency test: the engine minifies its own minified output and confirms it produces the same bytes. If the two ever differ, the page surfaces a warning under the output panel — a regression in the engine cannot ship unnoticed.
Worked examples
Frequently asked questions
Sources & references
- HTML Living Standard (WHATWG) — tokenization & parsing
- CSS Syntax Module Level 3 — tokenizer specification
- ECMAScript 2024 — lexical grammar and automatic semicolon insertion
- JSMin (Douglas Crockford, 2001) — the canonical safe-JS minifier
Implementation cross-checked against these specifications on 2026-05-11. The transforms run from pure state machines — there are no external library dependencies, so the algorithms above are the definitive description of what the engine does.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.