CSS formatter
Everything runs in your browser; nothing is sent or stored.
- Paste your code into the "CSS code" field, and click "Format" or "Minify". Only whitespace, comments, and redundant semicolons change. Strings, url() addresses, CSS variable values (--name), and escapes are kept as written.
- Under "Indent", choose 2 spaces, 4 spaces, or Tab, and select or clear "Blank line between rules".
- Below the result, the tool shows the size in bytes before and after processing, and when you minify, the percentage saved. Minifying removes comments, except those that start with /*! (such as a license notice).
- Copy the result by clicking "Copy".
Formatting CSS code for reading and editing
CSS files from libraries and themes often come minified, on one long line, which makes them hard to read and makes it hard to find a specific rule. When you format the code, every declaration ends with a semicolon, every selector in a selector list appears on its own line, and the rules inside @media or @supports, as well as nested rules (CSS nesting), are indented by their nesting level. Comments stay where they are, so the formatted code is ready for editing and for comparing versions.
What changes when you minify CSS
Minification makes the file that the browser downloads smaller: extra spaces, line breaks, and comments are removed, as well as the last semicolon in each block. Comments that start with /*!, such as a license notice, are kept. The order of the rules and the values themselves do not change, so the meaning of the code stays the same, including in code with CSS variables and functions such as calc(). When the file is sent to the browser with gzip or Brotli compression, the transfer saving is smaller than the saving the tool shows, but the two methods complement each other.
When to use each mode
Keep your working file in the formatted version, with comments that explain its structure, and upload the minified version to the site, for example, as style.min.css. In a project with a build process, minification runs on every build, and the CSS formatter is handy for a quick check, for a single file, or for a CSS snippet embedded in a page. Formatting a minified file from an external provider lets you check which rules apply to a specific element before you add new rules.
CSS snippets and their minified result
margin : 0 auto ;becomesmargin:0 auto, and the space between the two values is kept, because it is part of the value.calc(100% - 10px)the spaces around the minus sign are kept, because without them the expression is not valid..card > h2becomes.card>h2, because the spaces around the>sign are not needed..card .titlethe space is kept, because it marks a descendant element.color: red !importantbecomescolor:red!important.
An HTML and CSS site can be hosted on static website hosting plans, with a free SSL certificate.
Related tools
CSS formatter FAQ
Can minification break the code?
No. Valid CSS code stays valid after minification, because minification removes only characters that do not affect the meaning. When removing a comment would join two parts of a value into one, the tool leaves an empty comment, /**/, in its place.
Does the tool shorten colors or remove unused rules?
No. The tool does not shorten values or merge rules, so a six-digit color code stays as written and is not shortened to three digits. Removing unused rules requires checking every page of the site, so it is not part of minification.
Why do I get an error about an unclosed string, comment, or bracket?
Closing a string, comment, bracket, or url() automatically could change the meaning of the code, so the tool does not process the code until the open part is closed. The error message shows the number of the line where that part opens. A closing curly brace missing at the end of the code is added in the result, following the CSS rules.
Can I format SCSS or Less code?
No. The CSS formatter is designed for CSS code, including CSS nesting, and not for SCSS or Less code. SCSS and Less have syntax that does not exist in CSS, such as comments that start with two slashes, so the result may be wrong or an error message may appear. Convert the code to CSS before you format or minify it.
Can I format CSS inside an HTML page?
Yes. You can paste the content of the style tag into the CSS formatter, without the tag itself. In the "HTML formatter" tool, the content of the style tag stays as written.
What is the maximum size of a CSS file I can format?
The input can be up to 1 MB, and the result can be up to 4 MB. Nested blocks are processed up to a depth of 128 levels.