CSS Formatter and Minifier
Beautify messy CSS with clean indentation or minify it with csso, and see the size before and after. Runs in your browser; nothing is uploaded.
How to format or minify CSS
- Paste your stylesheet, or click Open a file to load a
.cssfile (up to 10 MB). - Choose the Indentation (2 spaces, 4 spaces or a tab) and whether you want a Blank line between rules.
- Click Format (beautify) to get readable code, or Minify to get the smallest version.
- For minification, keep Merge rules when minifying ticked for the best result, and Keep /*! comments */ ticked to preserve license headers.
- Copy or download the result. The status line shows the size before and after, in bytes, and the percentage saved.
If a brace is missing, the tool stops and tells you on which line the unclosed { or the extra } is, instead of producing broken output.
Beautify: readable, consistent CSS
Format (beautify) uses js-beautify, the formatter found in many code editors. It puts every declaration on its own line, indents the content of each rule and of at-rules such as @media and @supports, writes each selector of a group on its own line, and adds a space after the colon of each declaration. Existing blank lines are kept (at most one in a row), so the logical sections of your file stay visible. The formatter never changes values, the order of rules or the meaning of selectors: it only changes whitespace.
This is useful to read minified CSS from a website, to review a stylesheet generated by a tool, or to clean up a file edited by several people with different habits.
Minify: smaller CSS with csso
Minify uses csso (CSS Optimizer), a structural minifier. Beyond removing whitespace and comments, it rewrites the stylesheet into an equivalent, shorter form:
- colors are shortened (
#ff0000becomesred,#ffffffbecomes#fff); - units and zeros are simplified (
0pxbecomes0,0.5embecomes.5em); - duplicate declarations are removed and shorthand properties are merged when it is safe;
- with Merge rules when minifying, rules with identical declarations are grouped (
a{color:red} b{color:red}becomesa,b{color:red}) and overridden declarations are dropped.
Restructuring is safe for normal stylesheets, but it moves declarations. If your CSS relies on a very specific cascade order, for example browser hacks, untick the option: csso will then only compress each rule in place.
Comments are removed, except “important” comments that start with /*!, which are commonly used for licenses. Untick Keep /*! comments */ to remove them as well.
Size before and after
The status line compares the size of the input and of the result in UTF-8 bytes. Beautified code is usually larger than the original; minified code typically saves 20 to 50 % on hand-written CSS. Remember that servers also compress files with gzip or Brotli, so the transfer saving is smaller than the raw figure, but minification still reduces parsing time and the size of cached files.
Frequently asked questions
Is my CSS sent to a server?
No. Both libraries run in your browser. Your stylesheet never leaves your computer, which also means the tool works offline once the page is loaded.
Can I format SCSS or Less?
Formatting generally works for simple SCSS and Less, because the syntax is close to CSS. Minification does not: csso only understands standard CSS, so compile your preprocessor code first.
Why is my minified CSS different from what I expected?
csso may reorder or merge rules when Merge rules when minifying is ticked. The resulting CSS applies the same styles. If you want each rule kept where it is, untick the option.
Does the tool validate my CSS?
Only partly. It checks that braces and comments are balanced and reports the line of the problem. Invalid property names or values are kept as they are, since browsers ignore unknown declarations.
What happens to vendor prefixes and custom properties?
They are kept. Vendor prefixes such as -webkit- and custom properties (--main-color) are preserved by both formatting and minification.
Related tools
- HTML Formatter Beautify messy HTML with clean indentation, or minify it safely, in your browser. Inline CSS and JavaScript are formatted too. Nothing is uploaded.
- JavaScript Formatter and Minifier Beautify minified JavaScript, minify it with Terser, or check its syntax with the exact line and column of any error. Runs in your browser only.
- CSS Gradient Generator Create linear, radial and conic CSS gradients with a live preview. Add and drag color stops, set the angle and copy clean CSS code in one click.