Code Minifier
CodeStrip whitespace and comments from HTML, CSS, or JavaScript to reduce file size. Runs entirely in your browser — your code is never uploaded anywhere.
What is a Minifier?
The Code Minifier strips whitespace, indentation, newlines, and optionally comments from CSS, HTML, or JavaScript source code, producing the smallest valid representation of the same code that executes or renders identically in the browser. It is the essential last step before deploying static assets to production.
Code written for humans is verbose by necessity. Indentation, blank lines between rules, descriptive comments, and generous spacing around operators all help developers read and maintain the code — but they add bytes the browser downloads and processes without any runtime benefit. A formatted CSS file with 200 lines might minify to 20 characters per rule instead of 7 lines per rule:
/* Before — 8 lines */
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
/* After — 1 line */
body{margin:0;padding:0;font-family:sans-serif}
The minified output is semantically identical: the browser applies exactly the same styles. The difference is in file size, which directly affects load time, CDN egress cost, and parse time.
The Code Minifier supports three languages with language-appropriate rules. CSS minification removes whitespace around structural characters while preserving values. HTML minification collapses inter-tag whitespace without affecting content. JavaScript minification removes whitespace around operators and punctuation. All three optionally strip comments.
All minification runs entirely in your browser — no code is ever uploaded or stored. Use the CSS Formatter to go back to a readable form if you need to edit minified code, or the JSON Minifier for JSON payloads.
How to use this Minifier calculator
- Paste your CSS, HTML, or JavaScript into the Code input box.
- Select the correct Language from the dropdown: CSS, HTML, or JavaScript.
- Choose whether to Remove comments (enabled by default).
- The Minified Code appears instantly in the output box.
- Click Copy to copy the minified code to your clipboard.
Formula & Methodology
Each language uses a targeted set of string transformations applied in order: CSS: 1. Strip block comments (/* ... */) if Remove comments is enabled. 2. Remove whitespace surrounding structural characters:{,},;,:,,,>,~,+. 3. Collapse all remaining whitespace runs to a single space. 4. Trim leading and trailing whitespace. HTML: 1. Strip HTML comment nodes (<!-- ... -->) if Remove comments is enabled. 2. Collapse whitespace between>and<(inter-tag whitespace) to nothing. 3. Collapse runs of 2+ spaces to a single space. 4. Trim. JavaScript: 1. Strip block comments (/* ... */) if Remove comments is enabled. 2. Strip single-line comments (// ...) if Remove comments is enabled (approximated — may not handle comments inside strings). 3. Remove whitespace surrounding operators and punctuation:=,+,-,*,/,%,&,|,^,!,<,>,?,:,,,;,{,},(,),[,]. 4. Collapse remaining whitespace runs to a single space. Before (CSS):css /* Main styles */ body { margin: 0; padding: 0; font-family: sans-serif; }After:css body{margin:0;padding:0;font-family:sans-serif}