Skip to content
Utilboxes

CSS Formatter

Paste a stylesheet and press Format for consistent indentation, or Minify to remove comments and whitespace, usually saving 20–35% before gzip. Nested rules, media queries, keyframes and native CSS nesting indent correctly, and strings and url() values are never misread. Values and rules are not rewritten. Nothing is uploaded.

Runs entirely in your browser

Updated

How to use the CSS Formatter

  1. 1Paste your stylesheet.
  2. 2Press Format to expand it, or Minify to compress it.
  3. 3Choose indentation and whether each selector goes on its own line.
  4. 4Copy or download the result.

How it works

The formatter walks the stylesheet character by character, tracking brace depth so nested structures indent correctly. That handles media queries, supports queries, keyframes and native CSS nesting, all of which put rules inside rules.

Strings, url() values and comments are tracked as their own states, so a semicolon inside a url() or a brace inside a string does not confuse the depth counter — a common failure in naive formatters.

Minifying removes comments and unnecessary whitespace, collapses the space around braces, colons and semicolons, and drops the final semicolon in each block. It deliberately stops short of rewriting values or merging rules, since those transformations can change behaviour in edge cases.

Everything runs in this page. Nothing you paste is transmitted, logged or stored, which is what makes it safe to drop a production payload in here while you are debugging.

Tips and common mistakes

  • Put each selector on its own line for long selector lists; it makes diffs easier to read.
  • Keep the formatted stylesheet as your source and minify only for production.
  • Minifying here never rewrites values or merges rules, so it cannot change how the styles behave.
  • Format a stylesheet copied from browser developer tools to make it readable again.

Frequently asked questions

Does it handle CSS nesting and media queries?
Yes. Brace depth is tracked properly, so nested rules, media queries, supports blocks and keyframes all indent correctly.
Are my comments kept?
Formatting keeps them. Minifying removes them, which is usually what you want in production.
How much does minifying save?
Usually 20–35% on a formatted stylesheet before gzip. Well-organised CSS with lots of indentation saves the most.
Can minifying change how my styles work?
It should not. Only comments and unnecessary whitespace are removed, and the last semicolon in each block is dropped; values and rules are left as they are.
Can I choose the indentation?
Yes. Choose the indentation and whether selectors in a list go on separate lines.
Is my stylesheet uploaded?
No. It is formatted in your browser.

Guides