CSS Minifier
Compress CSS by removing whitespace and comments
Paste your CSS above
π No upload β runs entirely in your browser. Your CSS never leaves your device.
Related Tools
What Is the CSS Minifier?
The CSS Minifier compresses your stylesheet by removing every character that the browser ignores: whitespace (spaces, tabs, newlines), code comments, and the optional trailing semicolon before a closing brace. The output is a single, compact line of CSS that produces exactly the same visual result as your original file β just in fewer bytes.
Processing happens entirely inside your browser. Your stylesheet is never uploaded to a server, logged, or stored. You can safely paste proprietary stylesheets, internal design tokens, or sensitive class names without any privacy concern.
How to Use This CSS Minifier
- 1.Paste your CSS into the left panel. This can be a single rule, a full stylesheet, or anything in between β there is no size limit.
- 2.Click Minify CSS. The minified output appears in the right panel instantly.
- 3.Check the stats row at the bottom: original size, minified size, and the percentage reduction.
- 4.Click Copy to copy the minified CSS to your clipboard, ready to paste into your production file.
- 5.Click Clear β to reset both panels and start with a new stylesheet.
Example: open your browser's DevTools, copy the CSS from the Styles panel for a component, paste it here, and get the compressed version to inline in a critical-CSS snippet in your HTML <style> tag.
What CSS Minification Removes
CSS minification targets five categories of redundant characters:
- Whitespace. Every space, tab, and newline that surrounds a structural character β a brace, colon, semicolon, or comma β is removed.
.foo { color: red }becomes.foo{color:red}. - Standard comments. Everything between
/*and*/is stripped. Comments serve developers reading source code; the browser ignores them entirely. Removing them has zero effect on rendered output. - Trailing semicolons. The last declaration inside a rule block does not need a semicolon before the closing brace.
color:red;becomescolor:redas the last rule. - Blank lines and indentation. Multi-line formatted CSS collapses to a single continuous line, eliminating line-break overhead.
- Nothing important. Rule names, property names, values, selectors, and the logical structure of the stylesheet are untouched. The minifier does not rewrite, merge, or reorganize rules.
Important Comments (/*!) and When to Use Them
By convention, a CSS comment that begins with /*!is an βimportant commentβ and is preserved by compliant minifiers. This tool honors that convention. Here is a typical example you would find at the top of an open-source CSS framework:
/*! * Bootstrap v5.3.0 * Copyright 2011-2023 The Bootstrap Authors * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) */
This comment cannot be removed without violating the MIT license terms. By writing /*!, the authors signal to minification tools that the comment must survive into the production build. If you write your own CSS libraries or design systems intended for public distribution, use /*! for your license block and /* for everything else.
CSS Minification and Web Performance
Every byte saved in CSS reduces the time before the browser can render your page. CSS is a render-blocking resource β the browser must download and parse the entire stylesheet before it can paint a single pixel. A 100 KB stylesheet that takes 200 ms to download over a 4G connection becomes a 70 KB file taking 140 ms after minification, a 60 ms saving that directly improves your Largest Contentful Paint (LCP) score.
The gains compound when you combine minification with server-side compression. Gzip typically reduces minified CSS by an additional 70β80%, and Brotli compression can reach 80β85%. The combination of minification plus compression consistently yields files 85β92% smaller than the original formatted source. For a stylesheet that started at 150 KB, the final transfer size can be as low as 12β22 KB.
For critical CSS β the above-the-fold styles needed for the initial viewport β minification is especially impactful. Critical CSS is commonly inlined directly in the HTML <head> to eliminate a render-blocking request entirely. Minifying the extracted critical CSS before inlining keeps the HTML document small and avoids inflating your Time to First Byte (TTFB).
Production vs Development: When to Minify
Development: Never minify CSS you are actively working on. Formatted stylesheets with comments make it far easier to understand and modify existing rules, navigate to the right selector, and understand why a layout decision was made. DevTools line numbers and property names map directly to your source, so inspecting and overriding styles is fast.
Production: Always deliver minified CSS to real users. Every page load from every user incurs the transfer cost of your stylesheet β minification is a free, permanent saving. When you deploy to production, your build tool (Vite, Webpack, Parcel, or Next.js) should handle minification automatically. The CSS Minifier here is most useful for one-off tasks: minifying a small snippet before inlining it, checking how much reduction a specific file will get, or compressing a stylesheet when you do not have a build pipeline available.
Source maps: If you ever need to debug minified CSS in production, generate source maps in your build pipeline. Source maps are separate files that map every minified byte back to the corresponding line in the original formatted source. DevTools automatically loads them and shows you the unminified code in the Styles panel β invisible to regular users but fully readable to developers.
How the Minifier Handles calc(), Strings, and Edge Cases
NaΓ―ve CSS minifiers that blindly strip all whitespace break two common patterns: arithmetic expressions in calc() and string values in the content property. This minifier handles both correctly.
calc() expressions: The CSS specification requires spaces around the + and - operators inside calc(). Without them, a value like calc(100% - 20px) becomes invalid. Before minifying, this tool extracts all calc(), min(), max(), and clamp() expressions, stores them verbatim, and restores them after whitespace removal.
String values: The content property and attr() expressions can contain quoted strings with semicolons, colons, or spaces that must not be touched. For example, content: "Step 1: Click here" must remain intact. This tool extracts all quoted strings before processing and restores them unchanged.
Data URIs in url(): Inline images encoded as base64 data URIs in url() values contain characters like +, /, and ; that would be corrupted by whitespace-removal logic. All url() values are extracted and protected before minification and restored verbatim afterward.
CSS Minification in Modern Build Pipelines
For ongoing projects, build tools handle CSS minification automatically so you never need to do it manually. Here is how the major ones work:
- Vite: Uses esbuild for CSS minification by default in production builds. Run
vite buildto get minified CSS output indist/. - Next.js: Minifies CSS automatically with
next build. No configuration needed for CSS files imported in your components. - Webpack: Uses css-minimizer-webpack-plugin (wrapping cssnano) in production mode. Enabled by default when you set
mode: 'production'. - Parcel: Minifies CSS automatically in production builds β no plugin or config required.
- Manual pipelines: If you manage your own pipeline,
cssnanovia PostCSS is the most widely used programmatic option for deep optimization, whileclean-cssis a fast alternative. This online tool is a quick manual option for one-off files or when you want to inspect the minified result before committing it.