DevTools Pro · All tools · About

Code Minifier

About the Code Minifier

This code minifier shrinks JavaScript, CSS, HTML and JSON by removing comments and unnecessary whitespace, and shows exactly how many bytes you saved. Variable names are never renamed, so the minified code behaves the same as the original.

What is code minification?

Minification rewrites source code into the smallest form that still means the same thing to the browser or parser. Indentation, line breaks and comments help people read code, but they are dead weight for the machine running it.

For example, the CSS rule .card { color : #333; } minifies to .card{color:#333}. The browser applies exactly the same style.

How each language is minified

JavaScript: comments and whitespace are removed, but a line break is kept wherever automatic semicolon insertion needs it, so code written without semicolons still runs. Strings, template literals and regular expressions are read as whole tokens and left intact, so "https://a.com//b" is not mistaken for a comment.

CSS: comments and spaces around { } ; : , > are dropped and the last semicolon in each block is removed. HTML: comments are removed (IE conditional comments are kept), runs of whitespace collapse to one space, inline <script> and <style> blocks are minified too, and <pre> and <textarea> content is kept verbatim. JSON is parsed and re-serialized without whitespace.

Minifying vs uglifying vs gzip

Minifying removes characters that do not affect behavior. Uglifying or mangling (what Terser and UglifyJS do by default) goes further and renames local variables to single letters, which saves more but makes stack traces harder to read without source maps.

Gzip and Brotli compression on the server are separate and stack with minification. Ship minified files and enable compression for the best result.

How to Use the Code Minifier

  1. Pick the language from the dropdown: JavaScript, CSS, HTML or JSON.
  2. Paste your code into the Input box, or click Load sample to see an example.
  3. Read the result in Minified output. It updates as you type.
  4. Check the Original, Minified and Saved figures to see the size reduction.
  5. Click Copy or Download (saved as minified.min.js, .css, .html or .json).

Frequently Asked Questions

Is my code uploaded anywhere?
No. Minification runs in your browser with a built-in tokenizer. Your code never leaves your device.
Will minified JavaScript still work?
Yes, as long as the input is valid. The minifier only removes comments and whitespace and keeps line breaks that semicolon insertion depends on. Invalid input such as an unterminated string shows an error instead of output.
Why is the saving smaller than with Terser or esbuild?
Those tools also rename variables and rewrite expressions. This tool deliberately does whitespace and comment removal only, which is safer and keeps the code readable in DevTools.
Does it keep license comments?
No. All JavaScript and CSS comments are removed, including /*! */ license headers, so add any required notice back after minifying.
Can I reverse minification?
Mostly. Use the Code Beautifier to re-indent minified code. Removed comments cannot be recovered.
Why does JSON minify fail?
The JSON is parsed first, so trailing commas, single quotes or comments cause an error. Fix those or validate the JSON with the JSON Formatter.

Related tools