LocalExcelTool
Get started

CSS Formatter

Beautify CSS with clean indentation and line breaks.

Runs in your browserNo account neededFree

What is CSS Formatter

CSS formatting adds proper line breaks and indentation to selectors, properties and values, improving readability.

🔒 Everything runs in your browser. Nothing is uploaded.

What this tool actually does with your file

Where it runs
In your browser, on this page
Upload
None — the file never leaves your device
Offline
Works with the network disconnected

A tokeniser, not a CSS parser

The formatter tracks quote state and comment state while walking the input, so a brace inside a string — content: "}" — does not change the indent level, and a brace inside a comment is ignored. Indentation follows brace depth; declarations get one per line.

It does not build a CSS object model, so it cannot tell whether a selector is valid, whether a property is known, or whether an at-rule contains declarations or rules. That is deliberate: a formatter should never reject CSS that a browser accepts, and browsers accept a great deal that a strict parser rejects.

Modern CSS that confuses naive formatters

Nested rules, @layer blocks and @container queries all contain braces at the same level as declarations, so brace-counting indentation looks slightly off inside them even though the output is still valid. CSS custom properties are the sharper case: their values are arbitrary tokens, and a formatter that lowercases property values will corrupt a case-sensitive custom property reference.

Also check calc() and grid template areas. A formatter that inserts spaces inside calc() arithmetic is harmless, but one that rewrites quoted grid-template-areas strings breaks layout in a way that is hard to trace back to a formatting step.

What to verify after formatting

Diff the output against the input with whitespace ignored. If anything other than spacing changed, the formatter touched content it should not have — that is the one check that catches every class of corruption in a single pass.

Prettier and stylelint are the better long-term answer for a codebase, because they are stable and configured once. A browser tool is for inspecting a snippet from production, a snippet pasted out of an email, or a one-off clean-up where installing a toolchain is not worth it.

How to use it

  1. 1.Paste your CSS
  2. 2.Click Format
  3. 3.Copy the result

How CSS Formatter works under the hood

Formatters parse your input into a structure, then serialise it back with consistent indentation. That is why a formatter can also reveal a syntax error: if it cannot parse, it cannot print.

  1. 1

    Parse into a tree

    JSON goes through JSON.parse; YAML, XML, CSS and SQL use their own parsers. The parse either succeeds with a structure or fails at a line and column.

  2. 2

    Serialise with a fixed style

    Indentation width, key order and quoting are applied deterministically, so formatting the same input twice gives identical bytes.

  3. 3

    Show the error position

    When parsing fails, the message includes the position so the fix is obvious instead of guessed.

  4. Processing pipeline
Example: one-line API response → readable tree
what the API returns
Raw JSON
{"name":"Product A","price":1280,"tags":["sale","new"],"stock":null}
same data, 2-space indent
PathValue
name"Product A"
price1280
tags[0]"sale"
tags[1]"new"
stocknull

Formatting and minifying are inverse operations on the same data — no value changes. The formatter re-parses with JSON.parse, so a trailing comma or a // comment makes it fail with the parser's own message: JSON has neither. The highlighted null is a real value, not a missing one — a missing field would simply have no row.

Formatting is not validation

A formatter proves the document is syntactically parseable. It does not prove it is valid against a schema, and it does not check business rules. JSON with a duplicated key parses fine and silently keeps the last value.

What gets normalised

Comments are preserved in CSS and SQL but not in JSON, which has no comment syntax. YAML anchors may be expanded, and quote style may change. Keep the original when exact byte layout matters, such as signed payloads.

Verify it yourself

Formatting is deterministic and local — run it twice and compare.

  1. 1.Open DevTools on this page and switch to the Network tab
  2. 2.Keep the filter on Fetch/XHR and run the tool
  3. 3.Confirm no request carries your file — you should see only page assets and fonts

Frequently asked questions

What is CSS formatting?

It organizes rules with line breaks and indentation for readability.

Are comments preserved?

Yes. Comments and string contents are left intact.

What this kind of conversion cannot keep

Formatters parse the input into a tree and print it back with consistent indentation. If the input is invalid, you get the parser's error position instead of a silently mangled file — malformed JSON stays malformed rather than being «repaired» into something that is no longer yours.

More in Format