CSS Minifier and Beautifier, Free and Private
Minify CSS to save bytes, or beautify it with one declaration per line. Strings, urls, custom properties and calc() are kept intact, and errors show the line and column. Nothing is uploaded.
Turns 0px, 0em and similar into 0, for lengths only.
Turns #aabbcc into #abc when every pair repeats.
0 characters, 0 bytes
0 characters, 0 bytes
About the CSS Minifier
The CSS Minifier makes a stylesheet smaller by removing comments, whitespace and the last semicolon in each block, and the same page can also beautify CSS that is squeezed onto one line. Paste CSS into CSS and the result appears next to it as you type. In Minify mode a note gives the bytes before and after and the percentage saved. In Beautify mode each declaration goes on its own line with the indent you choose.
Your CSS never leaves your device. The code runs in the page, so nothing is uploaded, logged or stored, and it is gone when you close the tab. The minifying code is only downloaded the first time you type, so the page stays light until you use it.
How to use it
Steps
- Paste or type CSS into CSS.
- Choose Minify or Beautify under Mode.
- For Minify, leave Shorten zero lengths and Shorten hex colors on or turn either off. For Beautify, pick 2 spaces, 4 spaces or Tab.
- Press Copy or Download .css.
What minifying does
Comments are removed, and the whitespace around selectors, braces, colons and commas is dropped, while the spaces that mean something stay, such as the descendant space in e f or the space inside calc(100% - 2px). The last declaration of each block loses its semicolon, so a{color:red;margin:0;} becomes a{color:red;margin:0}. Windows line breaks and tabs disappear.
The two shortening options
- Shorten zero lengths turns
0px,0em,0.0remand-0pxinto0. It applies only to length units.0%,0s,0degand0frare left as written, because0alone would change their meaning. Zeros insidecalc(),min(),max(),clamp(),var()andenv()are kept, and so is the0pxin aflexshorthand such asflex: 1 1 0px, where a bare0is treated differently by browsers. - Shorten hex colors turns
#ffffffinto#fffand#aabbccinto#abc, but only when every pair of digits repeats, so#abcdefstays as it is. Things that only look like colors, such as an id selector#aabbcc, an attribute value, a string or aurl(), are never touched.
What is copied exactly
Strings and url(...) are copied exactly, including any 0px, #ffffff, /* x */, ; or } inside them. Custom property values, such as --gap: 0px 0px, are copied exactly apart from trimming at both ends, because their meaning depends on the code that reads them. Escapes in selectors, such as .\31 23, keep their trailing space.
Worked example
Input a {\n color: red;\n}\n is 20 bytes. Minified it is a{color:red}, 12 bytes. The percentage saved is
and the note reads Saved 8 bytes (40.0%): 20 bytes to 12 bytes. Minifying the result again changes nothing.
Beautify
Beautify puts each declaration on its own line ending in ;, puts each selector of a list on its own line, indents the rules inside @media and similar blocks, and separates rules with a blank line. Comments stay, each on its own line. Beautifying does not shorten anything: 0px and #ffffff stay as written. Minifying the beautified text gives the same result as minifying the original.
Errors name the line and column
If the CSS cannot be read, you get an error with the line and column and the offending line with a caret under it. The cases are an unclosed block, an unclosed string or comment, an unclosed url(, and a } that has no {. Related tools: the HTML Minifier and the HTML Formatter.
Frequently asked questions
Is my CSS uploaded?
No. Minifying and beautifying run in your browser, so the stylesheet is not uploaded, logged or stored. Closing the tab clears it. The code is downloaded the first time you type, and after that no request is made with your CSS.
Will minifying change how my page looks?
It is designed not to. Strings, url() values and custom property values are copied exactly, zero lengths are shortened only where a bare 0 means the same thing, and hex colors only when every pair repeats. Test the result before deploying, as with any minifier.
Why was my 0px not shortened?
Zeros are shortened only for length units, and never inside calc(), min(), max(), clamp(), var() or env(), in custom properties, or in a flex shorthand. Percentages, times, angles and fr units are also left alone, because 0 by itself would mean something different.
What does the error message mean?
It gives the line and column of the first problem, shows that line with a caret, and says what is wrong, such as a missing closing brace, an unclosed string or comment, an unclosed url(), or a closing brace with no opening one. Fix it and the result updates as you type.
Does beautify change my values?
No. It only changes layout: one declaration per line, one selector per line, indented nested rules and a blank line between rules. Values such as 0px or #ffffff are not shortened, and comments are kept.
Does it handle nested CSS and modern at-rules?
Yes. Nested style rules, media queries inside media queries, supports blocks, keyframes, font-face, import and charset are all kept with their meaning. Preprocessor syntax such as Sass or Less is not supported.