Skip to content

Instantly share code, notes, and snippets.

@caiguanhao
Created March 18, 2014 17:56
Show Gist options
  • Save caiguanhao/9625621 to your computer and use it in GitHub Desktop.
Save caiguanhao/9625621 to your computer and use it in GitHub Desktop.
Prettify CSS

There are many online tools out there that can prettify or beautify compressed CSS file. But some of them have bugs, for example, not recognizing the @media directive. The easiest way to prettify an online compressed CSS file is to do it in Google Chrome. Open Developer Tools and click Sources tab, select the CSS file and then press the "Pretty Print" button {}.

But there are problems too. Google Chrome does not add the semicolon after the last property or each rule. When you use these styles in LESS, you may get errors if you don't put a semicolon at the end. For example:

.example {
  background: #666\9
}

You'll get a ParseError: Unrecognised input error.

Use "Find and Replace" in your text editor, for example, Sublime Text 3, to add the semicolons. Find with this regular expression:

([^;}])
(\s*)\}

and replace with:

$1;
$2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment