Guide
Beautifying and minifying CSS stylesheets
By Logappradeep · ServiceNow developer
CSS is forgiving about whitespace: a whole stylesheet can live on one line and the browser parses it the same way. That makes minified CSS great for page weight and terrible for humans. A CSS formatter puts every rule on its own block and every declaration on its own line, so you can scan selectors, compare values and find the property that is overriding your layout.
What beautifying does
A CSS rule is a selector followed by a block of declarations, each a property: value pair ended by a semicolon. The formatter inserts a line break and two-space indent after each opening brace and after each semicolon, puts the closing brace on its own line, and leaves a blank line between rules. Selector lists are normalized to a comma followed by a single space. So this:
.btn{color:#fff;padding:8px 16px}.btn:hover{color:#eee}
turns into two clearly separated rules with one declaration per line, which is the layout most style guides and linters expect.
What minifying does
The Minify option goes the other way. It strips /* comments */, collapses whitespace, removes spaces around braces, colons, semicolons and commas, and drops the final semicolon before each closing brace because it is optional. The output is functionally the same stylesheet in fewer bytes. Minification is not optimization, though: it will not merge duplicate rules, remove unused selectors or shorten #ffffff to #fff. Build tools such as cssnano or Lightning CSS do that work as part of a production pipeline.
Practical uses
- Inspecting the compressed CSS of a site or a third-party widget to see how a component is styled.
- Tidying styles copied from browser DevTools before pasting them into your codebase.
- Producing a compact inline
<style>block for an email template or embed. - Making a diff between two versions of a stylesheet readable.
Edge cases to keep in mind
This formatter works on characters rather than a full CSS parser, so it treats every semicolon, comma and brace the same way. Watch values that contain those characters inside strings or URLs, such as content: ";", url(data:image/svg+xml;...) or font-family lists in quotes, and check them after formatting. Nested rules from Sass, Less or native CSS nesting and at-rules like @media are indented by brace depth, but deeply nested code may need a manual touch.
Keep a source copy of anything you minify. Comments often carry license headers or explanations that you will want later, and minified CSS should be generated from readable source rather than edited by hand. Everything here runs locally in your browser, and the input box remembers your last stylesheet between visits.