CSS Minifier & Beautifier
Shrink a stylesheet by removing comments and unnecessary whitespace, or re-indent minified CSS so you can read it. Strings, url() values and calc() spacing are left intact.
462 B → 359 Bsaved 103 B (22%)
Drop a .css file here or click to browse
Up to 5 MB. The file is read locally and never uploaded.
What this CSS minifier does
Browsers do not need indentation, line breaks or comments to understand a stylesheet. Minifying removes them so the file is smaller to download and parse. You normally get this for free from a bundler such as Vite or Next.js, but there are plenty of cases where you need it by hand: a snippet for an email template, a widget you paste into a CMS, a quick check of how much a third-party stylesheet weighs, or a single file on a static site with no build step.
The opposite problem is just as common: you open a production stylesheet in DevTools or download a theme and get one enormous line. Beautify mode turns it back into readable, indented CSS.
Unlike quick regex-based minifiers, this tool splits the CSS into tokens first (strings, comments, url() values, punctuation and words). Text inside quotes and URLs is copied exactly, so a URL such as https://cdn.example.com//img.png is not mistaken for a comment, and spaces in content: "a b" survive.
How to use it
- Paste your stylesheet into CSS input, drop a
.cssfile on the upload area, or click Load example. - Choose Minify or Beautify. The output updates as you type.
- In Minify mode, decide whether to Keep /*! … */ comments. Leave it on if the file includes a license header you are required to keep.
- Check the size line (original → result, bytes saved) and any warnings shown above the editors.
- Click Copy or Download .css (saved as
styles.min.cssorstyles.css).
Worked example
Input (201 bytes):
/* Buttons */
.btn, .btn-primary {
padding: 0.50rem 1.0rem;
margin: 0px;
width: calc(100% - 2rem);
background: url(https://cdn.example.com/img//bg.png);
}
.nav :hover {
content: "Go →";
}Minified output (152 bytes, 49 bytes or 24% smaller):
.btn,.btn-primary{padding:.5rem 1rem;margin:0;width:calc(100% - 2rem);background:url(https://cdn.example.com/img//bg.png)}.nav :hover{content:"Go →"}Notice what changed and what did not: the comment and indentation are gone, 0.50rem became .5rem, 1.0rem became 1rem and 0px became 0. The spaces around the minus sign in calc() stay (without them the expression is invalid), the double slash in the URL stays, the two spaces inside the string stay, and so does the space in .nav :hover.
What the minifier changes
- Comments are removed. A removed comment counts as a separator, so
a/**/bbecomesa brather than gluing the two words together. - Whitespace collapses and disappears next to
{ } ; , > ~ + !. Inside parentheses it is only removed after(,,and:, which keeps math operators andand (in media queries safe. - Semicolons: the last one in each block and empty duplicates (
;;) are dropped. - Numbers: leading and trailing zeros go (
0.50→.5,1.0px→1px), and zero lengths lose their unit outside functions. Percentages (0%in keyframes), times (0s) and anything insidecalc()keep their units because removing them there is invalid.
The warnings box reports an unclosed comment, an unclosed string or unbalanced braces and parentheses. Those are usually typos in the source and are worth fixing before you ship the file.
Limitations
This is deliberately a conservative minifier. It does not merge duplicate selectors, combine longhand properties into shorthands, shorten colors such as #ffffff, remove unused rules or add vendor prefixes. Build tools like cssnano or Lightning CSS do those structural optimisations with a full CSS parser. A space before a property colon (color : red) is kept, because without a full parser the tool cannot always tell a declaration from a nested selector. Input is capped at 5 MB, and Sass or Less syntax such as // comments is not understood: compile it to CSS first.
Tips
- Keep the readable source in version control and treat the minified file as a build artefact.
- Minification and gzip or Brotli compression stack: enable compression on your server as well.
- If a minified file behaves differently, beautify it and compare with the original side by side using the Text Diff tool.
- Working on markup too? The JSON Formatter and SQL Formatter do the same job for other languages.
Frequently Asked Questions
Is my CSS uploaded to your servers?
No. The minifier is plain JavaScript that runs in your browser, and dropped files are read locally with the File API. Your stylesheet never leaves your device.
Will minifying change how my page looks?
It should not. The tool only removes comments, whitespace that has no meaning, redundant semicolons and zeros, and it leaves strings, url() values, escaped characters and the spaces inside calc(), min(), max() and clamp() untouched.
Why is the space in "div :hover" kept?
Because it is a descendant combinator: "div :hover" matches any hovered element inside a div, while "div:hover" matches the div itself. Removing that space would change which elements the rule applies to.
How much smaller will my CSS get?
It depends on how much indentation and how many comments the file contains. Hand-written, well-commented CSS often shrinks by around a quarter; CSS that is already compact shrinks much less. The tool shows the exact byte count before and after.
Does it merge rules or shorten properties like cssnano does?
No. This is a safe whitespace-and-syntax minifier: it does not merge selectors, rewrite colors or combine longhand properties into shorthands. For those structural optimisations use cssnano or Lightning CSS in your build.
What does Beautify do?
Beautify puts each declaration on its own line, indents nested blocks such as @media, splits selector lists onto separate lines and adds a space after each property colon. It only adds whitespace, so the result is equivalent to the minified CSS.
Related tools
- UUID GeneratorGenerate RFC 4122 compliant UUIDs (v1, v4, v5) in bulk. Export as JSON, CSV, or plain text.
- Lorem Ipsum GeneratorGenerate Lorem Ipsum placeholder text in paragraphs, sentences, or words with optional HTML output.
- QR Code GeneratorGenerate customizable QR codes for URLs, text, emails, WiFi, vCards, and phone numbers.
- QR Code ScannerScan QR codes with your camera or from an image file directly in the browser. Copy the result, open safe links and see the decoded content type.
- Regex TesterTest, debug, and visualize regular expressions against sample text in real time with match highlighting.
- SQL Formatter & BeautifierFormat and beautify SQL queries with proper indentation, keyword capitalization, and syntax highlighting.
Found a bug or a wrong result? Report it.