Ttooleras
🎨

Beautify and indent CSS, SCSS, LESS code — configurable style, production-ready output. Free, private — all processing in your browser.

Advertisement

The CSS Formatter transforms messy, minified, or inconsistently-formatted CSS into clean, properly-indented output. Works with plain CSS, SCSS (Sass), LESS, and Stylus. Configurable formatting rules: indentation (2 or 4 spaces, tab), space inside braces, newline before opening brace (K&R vs Allman), one selector per line vs comma-joined, space around colons. Preserves comments and the original order of declarations. Perfect for cleaning up CSS from minified production builds, normalizing team code styles, or preparing CSS examples for documentation.

CSS is notoriously prone to inconsistent formatting. Different editors, different team members, and different preprocessors produce different styles. A well-formatted CSS file is dramatically easier to scan, review, and maintain — properties aligned, nested selectors indented, comments preserved. This formatter handles the mess in seconds. Complements our CSS Minifier (opposite direction) for production builds.

CSS Formatter — key features

Beautify minified CSS

Expand single-line CSS into properly indented, readable format.

Configurable indentation

2 spaces (default), 4 spaces, or tab. Match your project style.

Multiple CSS flavors

Plain CSS, SCSS, LESS — handles nesting, variables, mixins correctly.

One selector per line

Comma-separated selectors broken onto separate lines for cleaner diffs.

Preserves comments

All comments (`/* */`) kept in original position. Useful for documentation preservation.

Normalize spacing

Consistent space around colons, braces, commas. Professional appearance.

Validates syntax

Detects unclosed braces, missing semicolons, obvious errors.

100% client-side

Your CSS (possibly containing proprietary design system) stays in browser.

How to use the CSS Formatter

  1. 1

    Paste your CSS

    Minified or messy CSS, SCSS, or LESS. Tool auto-detects the language.

  2. 2

    Set indentation

    2 spaces (modern default), 4 spaces, or tab.

  3. 3

    Choose selector style

    Comma-joined (compact) or one per line (cleaner diffs).

  4. 4

    Click Format

    Clean, indented CSS appears instantly. All comments preserved.

  5. 5

    Copy or download

    Copy to clipboard or download as .css / .scss / .less file.

Common use cases for the CSS Formatter

Development

  • Clean up minified production CSS: When debugging production issues, format the minified CSS to read it.
  • Normalize team CSS: Team members commit CSS in different styles. Format consistently before committing.
  • CSS from CMS: WordPress, Drupal output CSS with inconsistent formatting. Clean before adding to theme.
  • CSS in JS extraction: Extract CSS from CSS-in-JS (styled-components, Emotion), format for standalone use.

Documentation

  • Tutorial and blog CSS examples: Code snippets in articles should be well-formatted for reader comprehension.
  • Design system documentation: Component CSS displayed in style guides should be clean.
  • Before/after examples: Show refactoring or improvement examples — format both sides for fair comparison.

Code review

  • Review bundled CSS: CSS from webpack/vite bundles is minified. Format before reviewing.
  • Compare CSS versions: Before/after CSS from different commits — format both for proper diff.
  • Audit third-party CSS: Understand what imported libraries do by formatting their CSS.

CSS Formatter — examples

Minified to formatted

Typical production CSS.

Input
.btn{background:#3498db;color:#fff;padding:8px 16px;border-radius:4px}.btn:hover{background:#2980b9}
Output
.btn {
  background: #3498db;
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
}
.btn:hover {
  background: #2980b9;
}

One selector per line

Cleaner for diffs.

Input
.btn, .button, input[type=submit] { background: blue; }
Output
.btn,
.button,
input[type=submit] {
  background: blue;
}

SCSS nesting

Indent nested selectors properly.

Input
.card{background:#fff;.title{font-size:20px;&:hover{color:blue}}}
Output
.card {
  background: #fff;
  .title {
    font-size: 20px;
    &:hover {
      color: blue;
    }
  }
}

Media queries

Properly indented.

Input
@media(max-width:768px){.mobile{display:block}}
Output
@media (max-width: 768px) {
  .mobile {
    display: block;
  }
}

Comments preserved

Section headers maintained.

Input
/*Buttons*/
.btn{color:#fff}/*Button primary*/.btn-primary{background:blue}
Output
/* Buttons */
.btn {
  color: #fff;
}

/* Button primary */
.btn-primary {
  background: blue;
}

Technical details

CSS formatting conventions (widely adopted):

Indentation:
- 2 or 4 spaces (most common), or tab.
- Consistent throughout file.

Braces:
- K&R / one-line style: .selector { (opening brace same line)
- Allman: .selector\n{ (opening brace new line) — rare in CSS

Declaration format:
``css
.selector {
property: value;
property: value;
}
``

- One declaration per line.
- Space after :.
- Semicolon after value (including last — makes diff-friendly).
- Consistent indentation.

Selector formatting:
- One selector per line when comma-separated:
``css
.button,
.btn,
[type="submit"] {
/* ... */
}
``

Grouping and comments:
- Separate logical sections with blank lines.
- /* Section comment */ at section starts.
- Inline /* trailing comment */ where needed.

Property ordering conventions:

Different projects use different rules:
- Alphabetical — easy to scan, harder to group related.
- SMACSS / Logical — position/display/box/text grouped.
- Concentric — outside-in (positioning → margin → padding → content).
- Random — do not do this.

Shorthand expansion:
Some formatters expand shorthands for clarity:

```css
/* Input */
margin: 10px 20px;

/* Expanded */
margin-top: 10px;
margin-right: 20px;
margin-bottom: 10px;
margin-left: 20px;
```

Rarely wanted — shorthand is more concise. This formatter preserves your chosen syntax.

SCSS-specific:
- Nested rules: indent properly.
- Variables ($) at top.
- @include, @extend lines.
- & parent selector reference.

LESS-specific:
Similar nesting, with @ variables.

Common issues handled:

- Missing semicolons (added).
- Extra semicolons (removed).
- Unclosed braces (detected).
- Inconsistent spacing (normalized).
- Comments position (preserved).

What it does NOT do:

- Change property ordering (alphabetize, etc.) — preserves author intent.
- Remove unused rules (use PurgeCSS, UnCSS).
- Combine duplicate selectors (use CSSnano, CleanCSS).
- Add missing vendor prefixes (use Autoprefixer).
- Lint CSS (use Stylelint).

Common problems and solutions

Formatter changes semantic order

This formatter preserves original declaration order. For alphabetical or logical ordering, use Stylelint with order plugin. Tool focuses on spacing and indentation only.

SCSS nesting too deep

Format is fine but 5+ levels of nesting is a code smell. Consider BEM naming instead of deep nesting. Flatter CSS is easier to maintain.

Comments look different

Some formatters collapse multi-line comments or add spacing. This tool preserves comment exactness while normalizing surrounding whitespace.

Vendor prefixes scattered

-webkit-, -moz-, -ms- prefixes for same property — formatter keeps your order. Autoprefixer (postcss-cli) generates them from modern CSS.

Minified content after formatting

If you format CSS that was already minified (no whitespace), result looks reasonable but may have lost some original intent (comments, grouping). Best on source CSS.

CSS variables and calc

var(--name) and calc(10px + 2em) preserved exactly. Whitespace inside function calls not normalized.

Very large files

Multi-megabyte CSS formats fine but may be slow. For huge legacy codebases, use CLI tools (prettier, stylelint).

Post-format lint rules

Formatting fixes style. Stylelint fixes semantic issues (unknown properties, non-standard values). Use both in your pipeline — format first, then lint.

CSS Formatter — comparisons and alternatives

CSS Formatter vs CSS Minifier: Formatter expands for readability. Minifier compresses for production. Opposite operations; lossless roundtrip. See our CSS Minifier.

This tool vs Prettier: Prettier is the industry-standard code formatter (JS, CSS, HTML, more). Runs in editor/CI. More opinionated; harder to configure. This tool is browser-based for ad-hoc formatting without installation. Both produce clean output.

Formatter vs Linter (Stylelint): Formatter fixes cosmetic issues (spacing, indentation). Linter fixes semantic issues (unknown properties, duplicate selectors, bad patterns). Use both.

CSS vs SCSS formatting: Same basic rules. SCSS has additional nesting and preprocessor features. This tool handles both.

Auto-format on save vs tool: Editor auto-format (Prettier integration) is best for daily work. This tool for one-off formatting, code from different sources, quick checks without editor.

Ordering plugin vs formatter: Stylelint with stylelint-order plugin orders properties (alphabetical, logical). Formatter preserves order. Use ordering when you want enforced consistency.

Frequently asked questions about the CSS Formatter

What does the CSS formatter do?

Takes CSS input and produces cleanly-indented, consistently-spaced output. Normalizes whitespace, fixes spacing around colons and braces, indents properly, splits multi-selector rules. Preserves declaration order, comments, and your chosen CSS approach.

Does it change my CSS semantics?

No. Formatter only changes whitespace and indentation. Selectors, properties, values, and order are preserved exactly. Your CSS behavior is unchanged after formatting.

Should I use 2 or 4 spaces for indentation?

2 spaces is the modern default (Prettier, Google, Airbnb style guides). 4 spaces is common in older codebases. Either works — consistency matters more than which you pick.

Does it support SCSS?

Yes. SCSS nesting, variables ($var), @include, @extend, parent selector (&) all handled correctly. LESS too. Specify language in the tool if auto-detection gets it wrong.

Why should I format my CSS?

Formatted CSS is easier to: (1) Read — properties and selectors visible at a glance. (2) Review — code review is faster. (3) Diff — changes show clearly in git. (4) Maintain — future changes easier. (5) Debug — can scan for bugs quickly.

Should I format CSS from production builds?

Production CSS is minified. To debug production issues, format the minified output to read it. Do not commit the formatted version as production — keep minified for serving.

Does this tool preserve comments?

Yes. All comments (/* ... */) are preserved in original positions. Even inline trailing comments. Useful for documentation you want to keep.

Can it reorder properties alphabetically?

No. Formatter preserves original order. For ordering, use Stylelint with order plugin. Alphabetical order is controversial — some prefer logical grouping.

Is my CSS private when using this tool?

Yes. Formatting happens entirely in your browser. CSS never uploads. Safe for proprietary design system code, internal tools, client projects.

What if my CSS has errors?

Tool attempts to format valid CSS. Significant syntax errors (unclosed braces, malformed selectors) may produce weird output or errors. Fix syntax errors with a linter before formatting.

Additional resources

Advertisement

Learn more

Explore more tools

200+ free tools that run in your browser.

Browse all tools →