Guide
CSS Minifier: Shrink or Beautify Stylesheets
How CSS minification and beautifying work in the browser, what is safe to remove, and when not to minify.
Quick Answer
Minify CSS removes comments and insignificant whitespace so the file is smaller to transfer. Beautify CSS (also called unminify CSS) expands a compact stylesheet with indentation so you can read it. Both runs stay in your browser.
Try the CSS Minifier and Beautifier →How It Works
CSS minification here is a local css minify pass: a small tokenizer splits the stylesheet into code, strings and comments. Minify drops comments and collapses code whitespace. Beautify walks the same tokens and inserts newlines and two-space indents at braces and semicolons. Therefore a css formatter pass does not need a network round trip.
What Minifying Cannot Remove Safely
Unused rules, duplicate selectors and verbose colour forms need a bundler that sees your HTML. This page refuses those guesses. Minify rewrites selectors is a myth here: selectors stay exactly as written. It only removes what CSS grammar treats as insignificant.
CSS Minifier Example
For example, paste
body { margin: 0; color: #333; } /* note */.
Minify returns body{margin:0;color:#333} and reports bytes saved.
Beautify turns a one-line file back into indented rules.
When to Minify or Beautify
Beautify when you inherit a minified vendor file and need to read a rule. Minify when you will ship hand-written CSS without another build step. Prefer a browser-only tool when the stylesheet might contain internal class names or comments you do not want uploaded.
Common Mistakes
Expecting unused-rule elimination from a tokenizer is the usual mix-up: minify CSS only drops comments and insignificant whitespace. Another mistake is minifying the only copy you still edit. Beautify first, edit, then minify as a last step.
Browser Minify vs Uploading to a Web Service
Browser minify vs build-pipeline minify is the real choice for production. A bundler can drop unused rules; this page cannot. An upload minifier vs a browser css beautifier and css formatter also trades convenience for privacy. Prefer the local path when a stylesheet contains internal class names or comments you do not want uploaded. Unminify CSS here stays on this device too. Checking how many bytes comments cost is what the minify status line reports.
Related Tools
You May Also Need
You may also need
- PX to REM ConverterConvert units before shipping the stylesheet
- JSON MinifierMinify JSON payloads the same way
Next steps
- Color Format ConverterConvert colour values used in the stylesheet