CSS Formatter and Minifier
FV-09Paste CSS and press Format for one declaration per line with consistent indentation, or Minify to remove comments and whitespace. Strings and url() values are kept exactly as written.
Runs in your browser. Nothing is uploaded.
CSS
Result
How to use it
- Paste your CSS into the input box, or open a .css file.
- Choose Format to indent it, or Minify to compress it.
- Pick 2 spaces, 4 spaces or Tab for the indent when formatting.
- If there is an error, the message gives the line where a string, comment or brace was left open.
- Copy the result or download it as a .css file.
What Format does
Format puts each selector and each declaration on its own line, indents the contents of every rule and at-rule, and puts a blank line between rules. Selector lists such as h1, h2 go one per line. It keeps your declarations in their order and does not change values, colors or units. Nested rules and media queries are indented one level more than their parent.
What Minify removes
Minify takes out every comment, including /*! license */ comments, collapses runs of whitespace and removes spaces around braces, semicolons, commas and > combinators. The last semicolon before a } is dropped. Text in quotes and unquoted url() values are copied as written. It does not shorten colors like #ffffff, remove zeros, merge rules or rename anything, so the saving is whitespace and comments only.
Checks before it runs
Both buttons first check the CSS for a string that is never closed, a comment with no */, an extra } and a { with no matching }. An unclosed string or comment is reported with its line number; an unclosed { is reported as a count. This is a structure check, not full validation, so a misspelled property or a bad value is not reported. A space before a colon is kept, since in a selector such as a :hover it means a different thing.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Unexpected } at line 4 with no matching {. | A closing brace has no opening brace before it. | Remove the extra } or add the missing { above it. |
1 block opened with { and never closed (missing }). | A rule or at-rule was started but not closed by the end of the CSS. | Add the missing } at the end of that rule. |
String starting at line 2 is never closed (missing "). | A quoted string has no ending quote on the same line. | Add the closing quote. The message names the quote character. |
Comment starting at line 1 is never closed (missing */). | A /* comment has no ending */. | Add */ where the comment ends. |
Questions people ask
How do I format CSS online?
Paste the CSS into the input box and choose Format. Each declaration goes on its own line, indented with 2 spaces, 4 spaces or a tab. Copy it or download a .css file. It runs in your browser and nothing is uploaded.
How do I minify CSS?
Paste your CSS and choose Minify. Comments are removed, whitespace is collapsed and the last semicolon in each rule is dropped. Strings and url() values are kept as written. Test the result on your site before you deploy it.
Does minifying remove license comments?
Yes. All comments are removed, including /*! ... */ comments that some tools keep on purpose. If your license requires the notice, add it back above the minified file or use a build tool that preserves it.
Will the minified CSS behave the same?
It should. It only removes comments and whitespace that CSS ignores, and it keeps strings and url() as written. It does not change values, so results such as 0px stay as they were.
Does it validate my CSS?
Only the structure. It reports unclosed strings, unclosed comments and unbalanced braces; strings and comments come with the line number. A misspelled property, an unknown value or a missing semicolon in the middle of a rule is not reported.
Does it support media queries and nesting?
Yes. At-rules such as @media are indented like any other block, and rules nested inside another rule are indented one level deeper when formatting. Minify keeps their structure.
About this tool
Format uses the js-beautify library and puts each selector and declaration on its own line. Minify is our own: it removes every comment, including /*! license */ comments, collapses whitespace, drops the last semicolon in each block, and keeps strings and url() values exactly as written. It does not shorten colors or numbers, merge rules or rename anything. Both check that strings, comments and braces are closed; an unclosed string or comment is reported with its line, and an unclosed { is reported as a count. Space before a colon is kept, because in a selector it means something.