CSS Formatter
CodeBeautify raw or minified CSS with proper indentation and one rule per line. Runs entirely in your browser — your stylesheets are never uploaded anywhere.
What is a CSS?
The CSS Formatter restructures raw, minified, or poorly indented CSS into a clean, readable stylesheet with consistent indentation, one declaration per line, and a blank line between each rule. It is the standard step between receiving or generating compact CSS and editing it as a human.
CSS delivered from a CDN, a bundler, or a third-party library is almost always minified — all whitespace removed so it transfers as few bytes as possible. This makes it fast to download but completely unreadable:
body{margin:0;padding:0;font-family:sans-serif}h1{color:#1A1A2E;font-size:2rem;font-weight:700}.container{max-width:1200px;margin:0 auto;padding:0 1rem}
The CSS Formatter expands this into a structured stylesheet where every selector opens on its own line, every declaration is on an indented line with a semicolon, and each rule is separated by a blank line — the format your editor would produce if you had written the CSS yourself.
The formatter also includes an optional property-sorting step that arranges declarations alphabetically within each rule block. Sorted properties eliminate inconsistency across a team's stylesheet contributions and make a specific property easy to locate by scanning vertically rather than reading every line.
All formatting runs entirely in your browser. No CSS you paste is ever sent to a server or stored anywhere. This makes it safe to use with proprietary stylesheets, internal brand tokens, or any CSS that contains confidential design details. You can also use the SQL Formatter and JSON Formatter for other structured text formats.
How to use this CSS calculator
- Paste your CSS into the Raw CSS input box — this can be minified, hand-written with inconsistent indentation, or copied from DevTools.
- Choose an Indent Size from the dropdown: 2 spaces (default) or 4 spaces.
- Optionally enable Sort properties alphabetically to arrange declarations in each block in A–Z order.
- The Formatted CSS output updates instantly in the output box.
- Click Copy to copy the formatted CSS to your clipboard for use in your editor or project.
Formula & Methodology
The formatter processes CSS in a single pass over the source string, treating{,}, and;as structural delimiters: 1. Strip block comments —/* ... */blocks are removed entirely before formatting begins. 2. Normalise whitespace — all whitespace runs (spaces, tabs, newlines) are collapsed to single spaces. 3. Scan for{— everything before it is the selector, printed on its own line followed by{. 4. Scan for}— the content between{and}is split on;into individual declarations, each printed as<indent><property>: <value>;. If sort is enabled, declarations are sorted alphabetically before printing. 5. Close the block —}is printed on its own line, followed by a blank line to separate rules. Before:css body{margin:0;padding:0;font-family:sans-serif}h1{color:#1A1A2E;font-size:2rem}After (2 spaces, sorted):css body { font-family: sans-serif; margin: 0; padding: 0; } h1 { color: #1A1A2E; font-size: 2rem; }