CSS Prettify
Prettify and format minified or messy CSS code instantly. Configurable indentation, brace style, and one-click copy or download.
About
Minified CSS reduces file size for production but makes debugging and auditing nearly impossible. A single missing semicolon in a 40,000-character one-liner can cost hours of manual tracing. This tool parses raw CSS character-by-character, reconstructs proper nesting hierarchy, and outputs cleanly indented code with consistent brace placement. It handles nested at-rules (@media, @keyframes, @supports), preserves string literals and url() references, and respects comment blocks without mangling their content.
The formatter does not validate CSS syntax. It operates as a whitespace and newline normalizer that relies on bracket-depth tracking. Malformed input with unbalanced braces will produce indentation drift proportional to the mismatch count. For critical stylesheets, pair this tool with a linter. Pro tip: always prettify vendor CSS before code review to surface overrides and specificity conflicts hidden in compressed output.
Formulas
CSS prettification is a deterministic text transformation. The formatter uses a depth counter d that increments on { and decrements on }. Each lineβs leading whitespace equals:
Where char is the chosen indent character (space or tab), size is the configured indent width, and d is the current bracket depth. The tokenizer state machine recognizes five contexts: normal, comment, single-quote string, double-quote string, and url-parens. Inside string or url contexts, all characters pass through unmodified. In normal context, the formatter applies these rules in order:
For selector-per-line mode, commas outside of value contexts trigger a newline. The algorithm is O(n) where n is the character count of the input.
Reference Data
| Option | Values | Default | Effect |
|---|---|---|---|
| Indent Character | Spaces / Tabs | Spaces | Controls the whitespace character used for each indent level |
| Indent Size | 1 - 8 | 2 | Number of indent characters per nesting level |
| Opening Brace | Same Line / New Line | Same Line | Places { on the selector line or the next line |
| Blank Line Between Rules | Yes / No | Yes | Inserts an empty line between top-level rule blocks |
| Selector Per Line | Yes / No | Yes | Splits comma-separated selectors onto individual lines |
| Align Colons | Yes / No | No | Pads property names so colons align within a block |
| CSS Minification | Standard | - | Removes all optional whitespace and comments |
| Comment Handling | Preserve / Strip | Preserve | Keeps or removes /* β¦ */ blocks |
| Max Line Length | Unlimited | β | Formatter does not wrap long values; manual wrap required |
| Trailing Semicolon | Always | Always | Ensures last declaration in a block ends with ; |
| @media Nesting | Supported | - | Correctly indents rules inside nested at-rules |
| @keyframes | Supported | - | Formats percentage selectors and their declarations |
| @font-face | Supported | - | Treats as standard block with property declarations |
| @import / @charset | Supported | - | Preserved on individual lines at document top |
| String Preservation | Always | - | Content inside quotes is never modified |
| url() Preservation | Always | - | Paths inside url() are never modified |