nutilz
πŸ—œοΈ

CSS Minifier

Compress CSS by removing whitespace and comments

Paste your CSS above

Minified output will appear here

πŸ”’ No upload β€” runs entirely in your browser. Your CSS never leaves your device.

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. 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. 2.Click Minify CSS. The minified output appears in the right panel instantly.
  3. 3.Check the stats row at the bottom: original size, minified size, and the percentage reduction.
  4. 4.Click Copy to copy the minified CSS to your clipboard, ready to paste into your production file.
  5. 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; becomes color:red as 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 build to get minified CSS output in dist/.
  • 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, cssnano via PostCSS is the most widely used programmatic option for deep optimization, while clean-css is 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.

Frequently Asked Questions

What is CSS minification?+
CSS minification is the process of removing all unnecessary characters from a stylesheet without changing its functionality. This includes whitespace (spaces, tabs, and newlines), code comments, and the last semicolon inside each rule block. The browser reads the minified CSS identically to the original β€” the only difference is file size. A stylesheet that is 50 KB when formatted can typically be reduced to 35–40 KB after minification, a 20–30% reduction in transfer size.
How much does CSS minification reduce file size?+
Most real-world CSS files are reduced by 15–35% through minification alone. Heavily commented or formatted stylesheets can see reductions closer to 40%. For example, Bootstrap's unminified CSS (approximately 232 KB) shrinks to roughly 197 KB minified β€” about 15% smaller. When combined with gzip or Brotli compression on the server, minified CSS is typically 80–90% smaller than the original uncompressed file, because compression algorithms work even better on the repetitive patterns left in minified output.
What is the difference between CSS minification and CSS optimization?+
Minification is a lossless transformation that only removes whitespace and comments β€” it preserves every CSS rule, property name, and value exactly as written. Optimization goes further: it restructures declarations, merges duplicate selectors, shortens color values (#ffffff β†’ #fff), removes redundant vendor prefixes, and reorders properties for better compression ratios. Tools like cssnano perform both minification and optimization. This CSS Minifier focuses on safe, lossless minification so you can apply it to any stylesheet without risk of unintended visual changes.
What are important comments (/*!) and are they preserved?+
Important comments begin with /*! instead of the standard /* β€” for example, /*! License: MIT */. They are conventionally preserved by minifiers because they typically contain copyright notices or license terms that must remain in distributed files for legal compliance. This tool preserves important comments exactly as written. Standard comments (/* ... */) have no meaning to the browser and are always removed. If you have documentation comments you want to keep in production, prefix them with /*! to signal that they should survive minification.
Should I minify CSS in development or only in production?+
Minify CSS only for production. During development, formatted and commented CSS makes debugging far easier β€” browser DevTools shows readable property names and line numbers that map directly to your source files. In production, minification saves bandwidth and speeds up page loads for every visitor. Most modern build tools β€” Webpack, Vite, Rollup, and Parcel β€” automatically minify CSS in production builds. If you need to debug a production site, use source maps, which allow DevTools to display the original formatted source even though the browser loads the minified version.
Does CSS minification break calc() expressions or pseudo-selectors?+
When done correctly, CSS minification does not break calc(), pseudo-selectors, or any other CSS feature. This tool specifically preserves the spaces inside calc() expressions (such as calc(100% - 20px)), because the CSS specification requires spaces around arithmetic operators in calc(). String values inside the content property (like content: "hello world") are also protected. Pseudo-selectors like :hover, :first-child, and ::before are handled correctly because the minifier only removes whitespace around structural delimiters, not inside selector names.
Can I minify CSS with media queries and @-rules?+
Yes, this tool handles all standard CSS @-rules including @media, @keyframes, @supports, @import, @font-face, and @charset. Media queries like @media (max-width: 768px) { ... } are fully supported and minified correctly. The nested block structure is preserved β€” only whitespace and comments are removed. All CSS selectors (class, ID, attribute, combinators, pseudo-classes, and pseudo-elements) are processed correctly. The output is valid, standards-compliant CSS that renders identically to the input in every browser.