
CSS Minifier & Beautifier
Paste your CSS to minify or beautify it instantly. 100% client-side - your code never leaves your browser.
Last reviewed: April 2026New to this tool? Click here for instructions
How to Use the CSS Minifier
To use the CSS Minifier, simply paste your CSS code into the input area on the left. Choose the mode you want - Minify to compress your CSS, or Beautify to format it with consistent indentation. The result will be displayed instantly in the output panel on the right. You can copy or download the output using the buttons provided.
When to Use the Tool in Real Workflows
Use the CSS Minifier when you need to reduce the file size of your CSS to improve page load times. It's particularly useful for production websites where every kilobyte counts. Additionally, use the Beautify mode when you receive minified CSS from a build tool or external stylesheet and need to read or debug it.
How It Works
The CSS Minifier works by removing unnecessary characters and formatting your CSS code. It strips comments, collapses whitespace, and reduces file size. The Beautify mode adds consistent indentation and line breaks, making your CSS easier to read. Both processes are done client-side, so your code never leaves your browser.
Tips, Edge Cases, or Limitations
For best results, ensure your CSS code is well-formed before minifying. Minification does not fix syntax errors; it only removes unnecessary characters. The Beautify mode assumes your CSS is already well-formed. Always test your minified CSS to ensure it renders correctly.
Frequently Asked Questions
This tool strips every redundant byte from your stylesheet in Minify mode, or re-formats a compressed wall of tokens into readable CSS in Beautify mode — all without touching a server. Paste your CSS, pick a mode, and the output is ready to copy or download instantly.
What This Tool Does
The CSS Minifier & Beautifier runs two distinct transformations on your stylesheet, selectable via the mode chip at the top of the tool pane. Both operations process your input entirely in the browser — your code is never transmitted to any server, logged, or stored beyond the current tab session.
Minify mode
Minify mode compresses a stylesheet for production deployment. It strips CSS comment tokens, collapses whitespace between declarations, removes spaces around colons and semicolons, eliminates trailing semicolons before closing braces, and shortens leading zeros in decimal values (e.g., 0.75rem → .75rem). The resulting file is semantically identical to the input per the CSS Cascading and Inheritance Level 3 specification — selector specificity, cascade order, and every computed value remain unchanged.
Beautify mode
Beautify mode does the inverse: it re-indents rules with consistent 2-space indentation, places each declaration on its own line, normalizes selector spacing, and inserts a blank line between rule blocks. This is the right mode when you need to read a vendor-compiled .min.css file during a debugging session. The CSS Formatter offers an equivalent beautify-only workflow if you prefer a dedicated interface.
Privacy model
🔒 Privacy: This tool runs 100% in your browser. Your input is not uploaded, stored, or logged anywhere outside your local session.
How to Use It
Step-by-step instructions
- Paste or type your CSS into the left input pane. Output appears in the right pane in real time — no button press needed.
- Use the mode chip at the top to toggle between Minify and Beautify. The default is Minify.
- Click Try Example to load a realistic 42-line Bootstrap 5 navbar override (~2.8 KB) if you want to see the tool in action before using your own stylesheet.
- Read the status bar below the output pane: it reports original size, minified size, and bytes saved as an absolute number and percentage.
- Click Copy to send the output to your clipboard, or Download to save it as a
.cssfile for deployment.
Worked example: Bootstrap 5 navbar override
The Try Example button loads a 42-line navbar stylesheet with inconsistent indentation, inline comments, redundant semicolons, and two @media blocks. The minified output drops from 2,847 bytes to 1,108 bytes — a 61.1% reduction — in a single pass. That transformation is shown in full below.
Interpreting the output stats bar
The status bar shows three values: Original (raw input byte count), Minified (output byte count after transformation), and Saved (the difference as both bytes and a percentage). For the navbar example, the bar reads: Original: 2,847 B → Minified: 1,108 B → Saved: 1,739 B (61.1%). Switching to Beautify mode on an already-formatted file will produce a negative "saved" figure — that is expected; beautified output is always larger than its source.
Worked Example: Bootstrap 5 Navbar Override
Inputs
- Source file
- 42-line Bootstrap 5 navbar CSS override with inconsistent indentation, inline comments, redundant semicolons, and a dead
@media printblock - Input size
- 2,847 bytes
- Mode
- Minify (default)
.navbar {
background-color : #1a1a2e ; /* dark navy */
padding-top: 0.75rem ;
padding-bottom : 0.75rem;
}
/* ===== Brand logo ===== */
.navbar-brand {
font-size : 1.35rem;
font-weight:700;
color :#e94560 !important;
letter-spacing : 0.04em ;
}
.navbar-nav .nav-link {
color: rgba(255,255,255,0.82) ;
padding-right : 1.1rem;
padding-left:1.1rem;
transition: color 0.2s ease-in-out ;
}
.navbar-nav .nav-link:hover ,
.navbar-nav .nav-link:focus {
color : #e94560 ;
}
/* Responsive breakpoints */
@media ( max-width : 991.98px ) {
.navbar-collapse {
background-color : #16213e;
padding: 1rem 1.25rem ;
border-radius : 0.5rem;
}
}
/* TODO: remove after redesign */
@media print {
.navbar { display : none ; }
}
.navbar-toggler {
border-color: rgba(233,69,96,0.6) ;
}
.navbar-toggler-icon {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28233%2C69%2C96%2C0.75%29' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}
Step-by-step transformation
- Paste the 42-line navbar CSS (~2,847 bytes) into the left input pane.
- Confirm the mode chip is set to Minify (default). Output appears immediately in the right pane.
- The status bar updates:
Original: 2,847 B → Minified: 1,108 B → Saved: 1,739 B (61.1%). - All
/* ... */comment tokens are stripped — the/* dark navy */inline note, the===== Brand logo =====section header, and theTODO: remove after redesignmarker are all gone. - The data URI inside
.navbar-toggler-iconis intact — theurl()value is not touched. - The
!importantannotation on.navbar-brandcolor is preserved; declaration weight is unchanged. - Click Copy or Download to save as
navbar.min.cssfor deployment.
Expected output
.navbar{background-color:#1a1a2e;padding-top:.75rem;padding-bottom:.75rem}.navbar-brand{font-size:1.35rem;font-weight:700;color:#e94560!important;letter-spacing:.04em}.navbar-nav .nav-link{color:rgba(255,255,255,.82);padding-right:1.1rem;padding-left:1.1rem;transition:color .2s ease-in-out}.navbar-nav .nav-link:hover,.navbar-nav .nav-link:focus{color:#e94560}@media(max-width:991.98px){.navbar-collapse{background-color:#16213e;padding:1rem 1.25rem;border-radius:.5rem}}@media print{.navbar{display:none}}.navbar-toggler{border-color:rgba(233,69,96,.6)}.navbar-toggler-icon{background-image:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28233%2C69%2C96%2C0.75%29' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e")}
0.75rem became .75rem, 0.82 became .82, spaces around colons and semicolons are gone, and trailing semicolons before each } are removed — all consistent with CSS Syntax Level 3 grammar.
Minification vs Beautification Explained
What minification removes
Minification targets characters that the CSS parser discards anyway. The full list: all /* ... */ comment tokens; leading and trailing whitespace inside property values; newlines between rules and declarations; spaces around colons, semicolons, and selector combinators; the final semicolon before a closing brace; and leading zeros in decimal values. None of these tokens carry semantic meaning per the W3C CSS Syntax Module Level 3 specification, which defines whitespace tokens between rules as safe to discard entirely. Selector specificity, declaration order, cascade resolution, and every computed value survive unchanged.
What beautification reconstructs
Beautification adds structure that aids human comprehension without altering machine interpretation. The tool inserts a newline after each {, places each declaration on its own indented line, adds a space after each colon, normalizes spaces between selector tokens and combinators, and separates rule blocks with a blank line. The output is cosmetically cleaner but functionally identical to the minified form. Neither operation alters specificity or cascade order — a fact worth stating clearly when explaining this to stakeholders who worry about "breaking styles."
When you need each mode
Use Minify immediately before deploying a stylesheet to production — or as a build step in your bundler. Use Beautify when you pull down a vendor's compiled .min.css and need to inspect it during a debugging session, or when a contractor hands you a single-line stylesheet and you need to review it for regressions. The two modes are complementary: beautify an unfamiliar file first, read and edit it, then minify before shipping.
Edge Cases and Gotchas
CSS custom properties (variables)
CSS custom properties such as --brand-color: #e94560 are preserved verbatim. Variable names are case-sensitive and semantically significant — --brandColor and --brandcolor are two different properties. The tool makes no attempt to rename, collapse, or merge variable declarations. Whitespace inside var() calls is normalized like any other function, but the variable name itself is untouched.
Media queries and @supports blocks
Nested @media and @supports blocks are minified recursively using the same token rules as top-level rules. A query like @media ( max-width : 991.98px ) collapses to @media(max-width:991.98px). Complex boolean expressions such as @supports (display: grid) and (not (display: inline-grid)) are handled correctly — internal whitespace collapses without touching the keyword logic.
calc() expressions
Whitespace around the + and - operators inside calc() is syntactically required per CSS Values and Units Level 4. A browser parsing calc(100%-2rem) will misinterpret the subtraction operator as a negative number prefix and produce an invalid expression. This tool retains exactly one space on each side of + and - inside calc(), while still collapsing any extra spaces around * and / where they carry no syntactic weight.
Data URIs and base64 content
Data URIs embedded in url() values are left completely untouched. Base64 padding characters (=, +, /) can be mistaken for CSS delimiters by naive regex-based minifiers, silently corrupting image or font data. Because this tool uses a tokenizer rather than a regex pipeline, the entire url() token is treated as an atomic unit and passed through as-is.
!important declarations
Every !important annotation is preserved. Minification never alters declaration weight — removing or collapsing !important would change cascade resolution and produce incorrect rendered output. The only formatting change is removing the space between ! and important where present, which is valid per the CSS grammar: color:#e94560!important is identical in effect to color: #e94560 !important.
Third-party frameworks like Bootstrap and Tailwind
Official Bootstrap and Tailwind dist packages already ship .min.css files alongside their unminified counterparts. Running a pre-minified file through a minifier again is harmless — the output will be semantically identical — but yields almost no additional byte savings because there is nothing left to strip. The correct workflow for a custom Bootstrap Sass compilation: build your Sass to unminified CSS output, then run that file through this tool. Beautifying a vendor .min.css first, then re-minifying after inspection, also produces a correct and semantically identical result.
License comment blocks
By default, all /* ... */ comments are stripped, including any /*! ... */ license headers. To preserve license attribution for legal compliance, enable the Keep license comments option in the tool before minifying — that option retains any comment whose first character after /* is !.
Performance Impact: Before and After Metrics
Typical savings across popular frameworks
The table below shows measured file sizes for five common stylesheets. Bootstrap 5.3's full CSS drops from roughly 232 KB to 197 KB (~15%) through minification alone — modest on paper, but that 35 KB is uncompressed. Tailwind's JIT build for a small project sees a ~20% reduction. FontAwesome 6's all.css, which includes substantial inline comments and generous whitespace, goes from 1.2 MB to 988 KB (~18%). The custom app stylesheet column represents a realistic internal stylesheet with heavy commenting and developer-style indentation, where savings reach 38%.
| Framework | Original Size (KB) | Minified Size (KB) | Bytes Saved | % Reduction | Gzipped Minified (KB) |
|---|---|---|---|---|---|
| Bootstrap 5.3 (full CSS) | 232 | 197 | 35 KB | 15% | 28 |
| Tailwind CSS JIT (small project) | 14 | 11.2 | 2.8 KB | 20% | 3.1 |
| FontAwesome 6 all.css | 1,228 | 988 | 240 KB | 18% | 142 |
| Bulma 0.9 | 204 | 168 | 36 KB | 18% | 24 |
| Custom app stylesheet (~150 KB) | 150 | 93 | 57 KB | 38% | 18 |
| Framework | Original (KB) | Minified (KB) | % Saved |
|---|---|---|---|
| Bootstrap 5.3 | 232 | 197 | 15% |
| Tailwind JIT | 14 | 11.2 | 20% |
| FontAwesome 6 | 1,228 | 988 | 18% |
| Bulma 0.9 | 204 | 168 | 18% |
| Custom App | 150 | 93 | 38% |
Downstream effect on page load
CSS is a render-blocking resource. Every kilobyte saved from a stylesheet reduces the time the browser spends in the "Parse Stylesheet" phase visible in Chrome DevTools' Performance panel. On a 50 Mbps connection with a typical 20 ms RTT, each 1 KB reduction in a render-blocking stylesheet shaves roughly 1–2 ms off time-to-first-paint. That figure scales non-linearly on slower mobile connections where transfer time dominates.
Combining with gzip or Brotli compression
Minification and server-side compression are complementary, not alternatives. Minified CSS compresses better than formatted CSS because repeated token patterns — {, :, ;, } — are denser and produce longer matching runs for the LZ77 stage. Bootstrap 5.3's minified CSS gzips to ~28 KB, compared to roughly 38 KB if the unminified version were served gzipped. Combined, minification plus gzip achieves an 85–90% reduction from the original developer-formatted file size. If your server supports Brotli (Content-Encoding: br), the numbers improve further — Brotli typically beats gzip by an additional 15–20% on text assets.
Behind the Scenes: How CSS Minification Works
Tokenization per CSS Syntax Level 3
The minification pipeline starts with a tokenizer, not a regex substitution. Per W3C CSS Syntax Module Level 3 §4, a conformant CSS tokenizer produces a stream of typed tokens: IDENT, STRING, HASH, NUMBER, PERCENTAGE, DIMENSION, URL, DELIM, WHITESPACE, and COMMENT. Each token type carries unambiguous semantics that a tokenizer-based minifier can reason about precisely.
Transformation passes
After tokenization, the output stream undergoes two passes. The first pass drops all COMMENT tokens unconditionally (or conditionally keeps /*! ... */ tokens when the license-preservation option is enabled). The second pass walks the remaining token stream and collapses adjacent WHITESPACE tokens: between any two non-whitespace tokens that are not inside a STRING or URL token, whitespace is reduced to a single space or removed entirely depending on syntactic context. Redundant semicolons immediately before a } token are dropped because the CSS grammar makes the final semicolon in a declaration block optional. Leading zeros in NUMBER tokens with a decimal point are stripped by normalizing the numeric value during reconstruction.
Why regex-only approaches break
A naive regex-based minifier — the kind that applies a sequence of s/ +/ /g-style substitutions — cannot distinguish whitespace inside a url("data:image/svg+xml,...") value from whitespace between declarations. The result is silent corruption of base64 padding or SVG data strings. The same problem affects content: "" strings with embedded spaces and calc() expressions where the whitespace around + and - is syntactically mandatory. A tokenizer-based approach avoids this entire class of bugs by treating STRING and URL tokens as opaque atomic units that pass through the pipeline unchanged.
| Token Type Removed | Example (Before) | Example (After) | Notes |
|---|---|---|---|
| Leading/trailing whitespace in values | color : #e94560 ; |
color:#e94560; |
Spaces around : and before ; are not significant per CSS Syntax Level 3 |
| Spaces around colons and semicolons | font-weight : 700 ; |
font-weight:700; |
Applies to all property declarations |
| Newlines between declarations | color:red;\n background:blue; |
color:red;background:blue; |
WHITESPACE tokens between declarations are dropped |
| Block comments | /* dark navy */ |
(removed) | /*! ... */ preserved when license option is on |
| Redundant final semicolons | padding:.75rem;} |
padding:.75rem} |
CSS grammar makes the last semicolon in a block optional |
| Leading zeros in decimal values | 0.75rem, 0.82 |
.75rem, .82 |
Saves 1 byte per occurrence; semantically identical |
| Redundant spaces inside rgba() / other functions | rgba(255, 255, 255, 0.82) |
rgba(255,255,255,.82) |
Space after comma is optional per CSS Values Level 4; leading zero removed |
| Spaces between selector combinators | .nav-link:hover , .nav-link:focus |
.nav-link:hover,.nav-link:focus |
Space around , list separator is not required by selector grammar |
calc() operator whitespace are explicitly excluded from removal.