CSS Formatter

Indent and format CSS rules, selectors and declarations.

  • Runs locally in your browser
  • No upload required

Try it

Paste a stylesheet. It is formatted in your browser and never uploaded.

Formatted CSS
.a { color:#fff; background:#000 }
Lines
4
.a {
  color:#fff;
  background:#000
}

Supported formats

Input
text, number
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Laid out 1 line(s) of CSS at 2-space depth.

How it works

  • Tokenised the stylesheet into selectors, punctuation, strings and comments.
  • Put each selector/block and declaration on its own line at a depth-based indent.
  • Preserved string literals, comments and url() contents exactly.
  • Selectors and declarations are preserved; only whitespace changes.
  • Output is 4 line(s); formatting it again changes nothing.

Methodology

  1. Tokenise the stylesheet respecting strings and comments so braces inside them cannot close a block.
  2. Emit selectors and blocks at a depth-based indent and declarations one per line.
  3. Re-emit strings and url() values verbatim.

Usage

  1. Paste or type a CSS stylesheet.
  2. Choose a 2- or 4-space indent.
  3. Run the formatter and copy the indented result.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Rule and declarations

jsonSelect to copy
{
  "text": ".a{color:#fff;background:#000}",
  "indentSize": 2
}

Media query

jsonSelect to copy
{
  "text": "@media (max-width:600px){.a{display:none}}",
  "indentSize": 4
}

URL and string preserved

jsonSelect to copy
{
  "text": ".a{background:url(\"a b.png\")}",
  "indentSize": 2
}

Limitations

Formatting versus minifying

Format a stylesheet while authoring or reviewing it; minify it for the served asset. Both tools keep the token stream identical.

Frequently asked questions

Are my string and url() values changed?
No. Strings and url(...) contents are tokenised as opaque text and copied exactly.
Does it fix invalid CSS?
No. Formatting never validates or repairs; it only changes layout whitespace.
Is my stylesheet uploaded?
No. The stylesheet is processed entirely in your browser.

Sources

  1. CSS Syntax Module Level 3 — W3C
  2. MDN Web Docs — CSS reference — MDN