CSS Beautifier
The CSS Beautifier untangles minified stylesheets into readable CSS: one rule per line, properties indented, selectors aligned. Perfect for inspecting production CSS or cleaning up generated styles.
How to Use
- 1
Paste your CSS — minified, single-line, or inconsistently formatted.
- 2
Click Beautify to expand rules onto separate lines with clean indentation.
- 3
Pick your indent size (2 spaces, 4 spaces, or a tab) to match your codebase.
- 4
Copy the formatted stylesheet or download it as a .css file.
Frequently Asked Questions
Does it support SCSS or Sass?
Will it fix broken CSS?
Can it sort properties alphabetically?
Does it handle media queries and keyframes?
Is my stylesheet uploaded to a server?
Why does the last property in each rule have no semicolon?
Does beautifying change what my CSS does?
Does beautifying happen as I type?
Can I download the beautified CSS?
What happens to my comments?
Generative Answer & AI Documentation
What is the CSS Beautifier?
The CSS Beautifier takes minified or inconsistently formatted CSS and returns it with one rule per block and one declaration per line, indented to show nesting. It is a hand-written text formatter, not a CSS parser: it strips comments out temporarily, collapses whitespace, breaks the stylesheet at braces, semicolons, and commas, then walks the resulting lines, indenting each one by its brace depth and restoring the comments at the end. A declaration line — a line containing a colon but no brace — is printed as property: value with a single space after the colon. Indentation is a choice: 2 spaces, 4 spaces, or a tab, from the dropdown above the editor. Beautifying runs when you click Beautify CSS; it does not update live as you type. The page starts with a sample already loaded — a container rule, two header rules, and a media query — so you can beautify it and see the shape of the output before pasting your own stylesheet. Everything runs in your browser, so proprietary design-system CSS never leaves your machine.
Why use CSS Beautifier offline?
Minified CSS is a single unreadable line, and production stylesheets are where the answers live when a layout breaks: which rule wins, what the media query actually changes, whether a property is overridden three rules later. Reading that from a minified file means reformatting it, and pasting a proprietary stylesheet into a server-side beautifier sends your design system to a stranger's logs. This tool does the job locally, with no upload and no account. The trade is honesty about what it is: a brace-and-semicolon text formatter, not a parser. For ordinary stylesheets — selectors, declarations, media queries, keyframes — it produces clean, readable CSS that shows the cascade's structure at a glance. For preprocessor syntax and exotic values, it has limits, and they are stated below rather than hidden.
When should you use this tool?
Use it when you need to read a minified stylesheet from production, when a generated or vendored CSS file needs to be understood before you override it, or when an inconsistently formatted stylesheet needs one consistent layout before a review. Use it on standard CSS: selectors, declarations, media queries, keyframes, and font-face rules all indent as nested blocks. Do not use it as a validator or a linter — it never checks your CSS, never flags a missing brace, and reformats broken input as if it were fine. And do not feed it SCSS or Sass directly: compile to plain CSS first, then beautify.
Key Benefits
- Readable layout: one rule per block, one declaration per line, nesting shown by indentation.
- Indent choice: 2 spaces, 4 spaces, or a tab, to match your codebase.
- At-rules handled: media queries, keyframes, and font-face indent as nested blocks.
- Comments preserved: block comments are lifted out before formatting and restored afterwards.
- Property order preserved: declarations stay in their original order, so the cascade is unchanged.
- Copy or download: one click copies the stylesheet, another saves it as styles.css.
Common Use Cases
- Inspecting production CSS: expand a minified stylesheet to find which rule is overriding your layout.
- Reading generated styles: beautify CSS from a build tool or a framework so its structure is visible.
- Cleaning up before a review: give a stylesheet one consistent layout so the diff shows real changes.
- Learning a design system: read a vendored stylesheet rule by rule instead of as a single line.
- Preparing documentation: paste formatted CSS into docs or a ticket where the cascade needs to be visible.
Developer Notes & Best Practices
The formatter is a sequence of regular-expression replacements followed by a depth walk, and its behaviour follows directly from that code. First, block comments are extracted and replaced with placeholders, so a comment cannot confuse the brace counting, and they are restored at the end by string replacement — which means a comment can end up attached to the line its placeholder landed on, for example /* hi */a { when the comment preceded a selector. Then all whitespace is collapsed to single spaces, a newline is inserted after every { and every ; and before every }, and commas are followed by a space. The walk then tracks brace depth: a line starting with } dedents first, a line that is a declaration (it contains a colon and no brace) is split on its first colon and printed as property: value, and a line ending with { increases the depth for the lines after it. Three consequences are verified by running the function itself. First, the tool never adds a missing semicolon: the sample's last declaration in each rule has no semicolon in the minified input, and it has none in the output either — semicolons are preserved exactly as written. Second, spacing is only normalised inside declaration lines: a media query prints as @media (max-width:768px) { with the colon unspaced, because selector lines are printed as-is. Third, the formatter has no notion of strings: a brace inside a quoted value, such as content:"{", is treated as a real brace and breaks the indentation of everything after it. URLs survive because the declaration split rejoins everything after the first colon, so background: url(https://example.com/x.png) comes through intact.
Verified behaviour — what the formatter actually does
| Input | Output | Note |
|---|---|---|
| .a{margin:0;padding:1rem} | .a {\n margin: 0;\n padding: 1rem\n} | Last declaration keeps no semicolon — none is added |
| @media (max-width:768px){.a{padding:1rem}} | @media (max-width:768px) {\n .a {… | Media queries nest correctly, but the colon stays unspaced |
| /* hi */a{color:red} | /* hi */a {\n color: red\n} | The comment is restored attached to the selector line |
| a{color:red | a {\n color: red | A missing } is never flagged — the output just ends |
| a{content:"{"} | Mangled indentation | A brace inside a quoted string is counted as a real brace |
- Validate first, beautify second: this tool never flags errors, so run broken CSS through a validator before formatting it.
- Compile SCSS or Sass to plain CSS before beautifying — nested rules and variables are preprocessor syntax, not CSS.
- Check the last declaration in each rule: a missing semicolon in the input stays missing in the output.
- Match the indent setting to your codebase before copying, so the diff shows real changes, not whitespace noise.
- Keep the original minified copy if the file is served to production — commit the readable version, deploy the minified one.
Common Mistakes
- Expecting it to fix broken CSS: a missing brace is reformatted as-is with no warning — it is a formatter, not a linter.
- Feeding it SCSS directly: nested rules and & selectors are preprocessor syntax, so compile to plain CSS first.
- Assuming the last declaration gains a semicolon: it does not — a missing semicolon in the input stays missing.
- Pasting CSS with a brace inside a string value: content:"{" breaks the brace counting and the indentation after it.
- Expecting alphabetical properties: the beautifier preserves your original order, since reordering can change the cascade.
Limitations
This is a text formatter, not a CSS parser: it counts braces and semicolons with regular expressions and has no understanding of CSS syntax. It never validates or flags problems — a missing closing brace is reformatted silently with the indentation left open, and an unclosed comment is consumed by the comment pattern without warning. A brace inside a quoted string, such as content:"{", is treated as a real brace and mangles the indentation after it. Comments are restored by placeholder replacement, so a comment can land mid-line attached to a selector. Spacing is only normalised in declaration lines: selectors and at-rule headers are printed as written, so @media (max-width:768px) keeps its unspaced colon. The last declaration in a rule keeps whatever semicolon it had — a missing one is never added. SCSS-specific syntax such as nested rules with & and variables may not format correctly, and property order is preserved with no option to sort alphabetically.
Structured Input/Output Example
.container{margin:0 auto;padding:2rem}header h1{color:#3b82f6;font-size:2.5rem}.container {
margin: 0 auto;
padding: 2rem
}
header h1 {
color: #3b82f6;
font-size: 2.5rem
}Related Tools
HTML Formatter
HTML formatter: turn minified or messy HTML into clean, indented markup. Nested tags aligned, attribute spacing normalized — view-source, readable.
JavaScript Beautifier
JavaScript beautifier: re-indent minified or tangled JS with consistent indentation. Tokenizer-based — strings, regexes, comments preserved. Free, offline.
Color Converter
Color converter: translate colors between HEX, RGB, HSL and OKLCH with a live preview swatch. Type a hex code or pick visually, then copy clean CSS.