About the CSS Minifier
Paste a stylesheet and you get it back as one compact line. Comments, line breaks and indentation are stripped, along with the spaces around braces, colons, semicolons and commas. What you gain is a smaller file to upload, to inline in a page, or to fit into a field that has a size limit.
The minified CSS shows up in the Result box as soon as you paste, ready to copy. Treat the readable version as the file you edit, and publish the compressed one.
What minifying CSS removes
The minifier reads the stylesheet from start to end, keeping track of quoted strings, url() values and comments. Every block comment between /* and */ is deleted, including comments that span several lines. Every run of whitespace (spaces, tabs and line breaks) is collapsed to a single space, and any space next to { } ; or , or straight after a colon is removed, so "padding: 8px 16px;" becomes "padding:8px 16px;" and ".a, .b {" becomes ".a,.b{".
A space before a colon is treated with care. Inside a declaration such as color : red it is removed, but in a selector it means something: .list :first-child (any first child inside .list) is not the same as .list:first-child, so there the space is kept. Text inside quotes, such as content: "Note: a, b" or a font name, is copied exactly, and so is the inside of url(), including base64 data URIs.
Spaces that carry meaning between words are left in place. A shorthand value such as 8px 16px, a calc() expression like calc(100% - 20px), a descendant selector like .card p and the space in @media (min-width:768px) all survive, because none of those spaces sits next to one of the characters above.
Only whitespace and comments are touched. Colour codes are not shortened, zero units are not dropped, duplicate rules are not merged and the final semicolon in each block is kept. You get the same CSS, just written more tightly.
Assumptions and limits
- All /* */ comments are removed, including /*! ... */ licence banners that some libraries ask you to keep. Paste the licence line back at the top if the licence requires it.
- Whitespace inside a quoted string is never touched, so content: "Note: " keeps both of its spaces.
- Escaped characters in class names, such as Tailwind's .md\:flex or .\31 0, are kept with the backslash and any space that belongs to the escape.
- A semicolon or brace that is missing in the original stays missing; the minifier doesn't repair or validate the code.
- Text with no selector block, at-rule or property: value pair is rejected with a warning rather than minified.
Worked examples
Compress CSS for a button component
Ten lines with a comment, indentation and a blank line (116 characters) shrink to one line of 83 characters, about 28% smaller. The comment is gone and the grouped selector .btn:hover,.btn:focus is kept together.
Input:
/* Buttons */
.btn {
padding: 8px 16px;
border-radius: 4px;
}
.btn:hover,
.btn:focus {
background: #0a66c2;
}
Output:
.btn{padding:8px 16px;border-radius:4px;}.btn:hover,.btn:focus{background:#0a66c2;}Custom properties and a media query
Variables, var() references and media conditions all minify cleanly. In this 150-character sample the /*! licence banner is removed along with the whitespace, leaving 95 characters, about 37% smaller.
Input:
/*! theme v2 | MIT */
:root {
--brand: #0a66c2;
--gap: 16px;
}
@media (min-width: 768px) {
.grid {
display: grid;
gap: var(--gap);
}
}
Output:
:root{--brand:#0a66c2;--gap:16px;}@media (min-width:768px){.grid{display:grid;gap:var(--gap);}}Minify CSS for inline styles or email
HTML emails and some CMS fields want the styles inside a <style> tag, often with a length limit. Minifying first strips the comments and line breaks a browser doesn't need. A calc(100% - 20px) width and a "Open Sans", sans-serif font stack come through with their meaning unchanged.
Input:
.note::before {
content: "Tip: ";
font-family: "Open Sans", sans-serif;
width: calc(100% - 20px);
}
Output:
.note::before{content:"Tip: ";font-family:"Open Sans",sans-serif;width:calc(100% - 20px);}Before and after: what the CSS minifier does
| In the original | In the minified CSS |
|---|---|
| /* comment */ | Removed |
| Line breaks, tabs, indentation | Collapsed, then removed around punctuation |
| color : #333 ; | color:#333; |
| .a , .b { | .a,.b{ |
| margin: 8px 16px | margin:8px 16px (space between values kept) |
| calc(100% - 20px) | Unchanged |
| .list :first-child (descendant) | Space before the colon kept |
| "quoted text", url(data:...) | Copied exactly |
| #ffffff, 0px, last semicolon | Unchanged (no value optimisation) |
How to use the CSS Minifier
- Paste the CSS. Replace the sample in the Input Text box with your stylesheet; the counter under it shows the original length in characters.
- Check the minified line. The Result box shows the compressed CSS on one line as soon as you paste, with comments and extra spaces removed.
- Copy and save as .min.css. Press Copy, paste into a new file named, for example, style.min.css, and link that file from your pages.
Frequently asked questions
Does minifying CSS improve page speed?
Yes, a little, because the browser has fewer bytes to download. How much depends on how much of the file is comments and indentation: a well-commented stylesheet can lose a quarter or more of its size. If your server already compresses files with gzip or Brotli, the extra saving after compression is smaller.
Can minified CSS break my site?
It shouldn't. Only comments and whitespace that browsers ignore are removed: quoted text, url() values and a meaningful space in a selector such as .menu :hover are kept. What it won't do is repair CSS that was already broken, such as a missing brace, so test the minified file once like any other change before you publish it.
How do I unminify the CSS later?
Keep the original readable file as your source and minify a copy each time you publish. If you only have the minified version, the CSS Formatter on VelixaKit puts each declaration back on its own line, though the deleted comments are gone for good.
Is the licence comment at the top kept?
No. Every /* */ comment is removed, including ones that start with /*! which some build tools preserve. If you are minifying a library such as a framework or icon set, paste its licence comment back above the minified line.
Does it shorten colours or remove units from zero values?
No. #ffffff stays #ffffff and 0px stays 0px. Only comments and whitespace are removed. That costs a few extra bytes, but the output stays predictable and easy to compare with the original.
Is my stylesheet uploaded anywhere?
No. The CSS is minified by the page itself in your browser, as you type, and isn't sent to a server or stored, so private or unreleased styles stay on your computer.
This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.