ToolDeck

CSS Minifier

Minify CSS by removing whitespace and comments

Try an example

CSS Input

Minified CSS

Runs locally · Safe to paste secrets
Minified CSS will appear here…

What Is CSS Minification?

CSS minification is the process of removing all unnecessary characters from a stylesheet without changing its behavior. This means stripping whitespace, line breaks, comments, and redundant syntax such as trailing semicolons and unnecessary quotes. The browser parses minified CSS identically to the original. The W3C CSS Syntax Module defines the grammar; whitespace between tokens is optional except where it separates identifiers. Minification exploits this by collapsing everything down to the minimum required characters.

An online CSS minifier takes your formatted stylesheet and produces a compact version optimized for transfer size. Typical savings range from 15% to 40% depending on how much whitespace and how many comments the source contains. For a 50 KB stylesheet, that translates to 7–20 KB fewer bytes sent over the network on every page load. Combined with gzip or Brotli compression on the server, minification reduces the final transfer size further because the compressed output of already-minified CSS is smaller than compressing the formatted original.

Minification is a standard step in front-end build pipelines. Tools like cssnano, clean-css, and esbuild run minification as part of the build. But during development, you often need to minify a single snippet for testing, inline a critical CSS block, or check how much a stylesheet shrinks before adding it to a bundle config. That is where a browser-based CSS minifier is useful: paste CSS, get the minified output, copy it, and move on.

Before · css
After · css
/* Main navigation styles */
.nav {
  display: flex;
  align-items: center;
  padding: 1rem 2rem;
  background-color: #1e293b;
}

/* Links inside nav */
.nav a {
  color: #e2e8f0;
  text-decoration: none;
  margin-right: 1.5rem;
  transition: color 0.2s ease;
}

.nav a:hover {
  color: #818cf8;
}
.nav{display:flex;align-items:center;padding:1rem 2rem;background-color:#1e293b}.nav a{color:#e2e8f0;text-decoration:none;margin-right:1.5rem;transition:color .2s ease}.nav a:hover{color:#818cf8}

Why Use This CSS Minifier?

Paste any CSS and get minified output in milliseconds. No build tool configuration, no CLI commands, no accounts required.

Instant Minification
Output updates as you type or paste. You see the minified result and the byte savings immediately, without waiting for a build step.
🔒
Privacy-first Processing
All minification runs locally in your browser using JavaScript. Your CSS never leaves your device and is never uploaded to any server.
📦
Accurate Size Reporting
See the original size, minified size, and percentage reduction side by side. Useful for estimating performance gains before committing to a build pipeline change.
📋
No Login Required
Open the page, paste your CSS, copy the result. No sign-up, no rate limits, no feature gates. The full tool is available on every visit.

CSS Minifier Use Cases

Frontend Performance Optimization
Minify critical CSS before inlining it in the head element of your HTML. Smaller inline CSS means faster First Contentful Paint, especially on mobile connections.
Backend Email Templating
Email clients ignore external stylesheets and have strict size limits. Minify your inline CSS to keep email HTML under the clipping threshold (102 KB for Gmail).
DevOps & Build Verification
Compare your build tool's minified output against this tool to verify that cssnano or clean-css is configured correctly and producing optimal results.
QA Size Budgeting
Paste a vendor stylesheet to check its minified size against your performance budget. Determine whether it needs tree-shaking or replacement before adding it to the project.
Data Engineering & Web Scraping
When extracting CSS from crawled pages, minify it to normalize whitespace differences between sources before comparison or storage.
Learning CSS Optimization
Students can paste CSS and see exactly which characters the minifier removes. Comparing input and output teaches which parts of CSS syntax are meaningful to browsers versus purely cosmetic.

CSS Minification Techniques

A CSS minifier applies several transformations to reduce file size. Each targets a different type of redundancy in the source. The table below lists the main techniques and their typical savings on a formatted stylesheet:

TechniqueWhat It DoesTypical Savings
Whitespace removalStrips spaces, tabs, and newlines between tokens15–25%
Comment strippingRemoves /* ... */ block comments5–15%
Zero shortening0px → 0, 0.5 → .51–3%
Shorthand colors#ffffff → #fff, #aabbcc → #abc1–2%
Semicolon removalDrops the last semicolon before }<1%
Quote removalfont-family: "Arial" → font-family: Arial<1%

Savings percentages vary by input. Heavily commented files benefit more from comment stripping, while already-compressed files see smaller gains. The most reliable wins come from whitespace removal and shorthand optimization. Advanced minifiers like cssnano also merge duplicate selectors, collapse longhand properties into shorthands (margin-top + margin-right + margin-bottom + margin-left into margin), and remove overridden declarations.

Minification vs. Gzip Compression

Minification and compression are complementary, not interchangeable. They operate at different layers and stack on top of each other:

CSS Minification (this tool)
Operates at the CSS syntax level. Removes whitespace, comments, and rewrites shorthand values. Runs once at build time. The output is valid CSS that browsers parse directly. Typical reduction: 15–40% of the original file size.
Gzip / Brotli Compression
Operates at the byte level using general-purpose compression algorithms. Applied by the web server on every response (or pre-compressed at deploy time). Works on any file type. Typical reduction: 60–80% of the minified size. Using both together produces the smallest transfer size.

Code Examples

How to minify CSS programmatically in different languages and environments:

JavaScript (cssnano + PostCSS)
import postcss from 'postcss'
import cssnano from 'cssnano'

const input = `
.nav {
  display: flex;
  padding: 0px 1rem;
  color: #ffffff;
  /* TODO: update color */
}
`

const result = await postcss([cssnano]).process(input, { from: undefined })
console.log(result.css)
// → ".nav{display:flex;padding:0 1rem;color:#fff}"
Python (csscompressor)
import csscompressor

css = """
.nav {
  display: flex;
  padding: 0px 1rem;
  color: #ffffff;
  /* navigation styles */
}
"""

minified = csscompressor.compress(css)
print(minified)
# → ".nav{display:flex;padding:0 1rem;color:#fff}"
Go (tdewolff/minify)
package main

import (
	"fmt"
	"github.com/tdewolff/minify/v2"
	"github.com/tdewolff/minify/v2/css"
)

func main() {
	m := minify.New()
	m.AddFunc("text/css", css.Minify)

	input := ".nav { display: flex; padding: 0px 1rem; color: #ffffff; }"
	output, _ := m.String("text/css", input)
	fmt.Println(output)
	// → ".nav{display:flex;padding:0 1rem;color:#fff}"
}
CLI (cssnano / clean-css)
# Using cssnano via PostCSS CLI
npx postcss styles.css --use cssnano -o styles.min.css

# Using clean-css CLI
npx clean-css-cli styles.css -o styles.min.css

# Quick one-liner with Node.js
node -e "const CleanCSS=require('clean-css');console.log(new CleanCSS().minify('body { margin: 0px; }').styles)"
# → "body{margin:0}"

Frequently Asked Questions

What is the difference between CSS minification and CSS compression?
Minification rewrites the CSS source code to remove unnecessary characters (whitespace, comments, redundant syntax) while preserving identical behavior. Compression (gzip, Brotli) encodes the file's bytes into a more compact binary format at the transport layer. Minification produces smaller CSS files on disk; compression reduces the bytes sent over HTTP. Best practice is to apply both: minify first, then let the server compress the minified output.
Does minifying CSS break anything?
Standard minification preserves CSS behavior. Whitespace inside string values (like content properties) is preserved by all major minifiers. However, aggressive optimizations like merging selectors or reordering properties can change specificity or override order. If you use cssnano's default preset, these risky transformations are disabled. This tool performs safe minification only: whitespace removal, comment stripping, and shorthand optimization.
How much smaller does CSS get after minification?
Typical reduction is 15–40% of the original formatted file size. Well-commented files with generous whitespace see the upper end of that range. Already-compact CSS written without comments may only shrink by 10–15%. The exact savings depend on coding style, comment density, and whether the source uses longhand properties that can be collapsed into shorthands.
Should I minify CSS manually or use a build tool?
For production builds, always use a build tool (PostCSS with cssnano, esbuild, or webpack's css-minimizer-webpack-plugin). Automated minification runs on every build and catches all files. A browser-based minifier is useful for one-off tasks: inlining a critical CSS snippet, checking the minified size of a vendor stylesheet, or minifying a quick prototype before sharing it.
Can I minify SCSS or LESS with this tool?
This tool minifies standard CSS. SCSS and LESS are preprocessor languages that compile to CSS. Compile your SCSS or LESS to CSS first (using sass or lessc), then paste the compiled output here. Minifying raw SCSS syntax may strip comments that control compilation behavior, like //! preserve comments or @use annotations.
Is minified CSS harder to debug?
Yes, minified CSS is a single line with no formatting, which makes it difficult to read in DevTools. The standard solution is source maps. Build tools like PostCSS and esbuild generate .map files that let browser DevTools display the original formatted source while the browser loads the minified version. For production debugging without source maps, paste the minified CSS into a CSS formatter to restore readability.
What is the difference between a CSS minifier and a CSS compressor?
In common usage, the terms are interchangeable. Both refer to removing unnecessary characters from CSS to reduce file size. Some tools use 'compressor' in their name (like csscompressor for Python) but perform standard minification. The word 'compression' can also refer to gzip/Brotli encoding, which is a separate server-level process. If you see 'CSS compressor,' it almost always means minification, not gzip.