Skip to content
DoItJag

CSS Formatter

Make a stylesheet readable again, with each rule and declaration on its own line.

or drop a file here · .css, .txt · up to 20 MB

Options

About the CSS Formatter

A stylesheet taken from a production website is usually minified: every rule crammed onto one line, with no spaces and no comments. Theme files edited over the years drift the other way, with mixed indentation. The CSS formatter rewrites either kind into a clean, predictable layout so you can read and edit it.

When to use it

  • You want to understand or copy a style from a minified file on a live site.
  • A theme’s custom CSS box has grown messy and needs tidying before you change it.

Worked example

Load the button styles with Try an example, keep 2 spaces, and press Format CSS.

Each rule now opens with its selector on its own line, followed by one declaration per line, each ending with a semicolon. The grouped selector for hover and focus is split so that each selector sits on its own line. The media query keeps its nested rule indented one level deeper, and a space appears after each colon. The “Buttons” comment stays where it was.

What is and is not changed

  • Spacing, line breaks and indentation are normalised.
  • Missing final semicolons are added.
  • Colours, units and selectors keep their meaning.
  • The order of rules and declarations is never changed.
  • Comments are kept.

Wider Line width settings let long values, such as gradients and font stacks, stay on one line instead of wrapping.

Good to know

  • The formatter uses Prettier’s PostCSS parser, which also understands nesting and many Sass-style constructs, though it is aimed at plain CSS.
  • A missing brace or quote stops formatting, and its position is shown.
  • Formatting does not check whether a property or value is valid, so a typo such as “colr: red” is formatted, not flagged.
  • To make a stylesheet smaller instead, use the CSS minifier. For colour values, the colour code converter translates between hex, RGB and HSL.

How to use CSS Formatter

  1. Paste CSS or open a .css file.
  2. Choose the indentation and line width.
  3. Select Format CSS, check the result, then copy or download it.

Privacy: how it works

Everything happens in your browser. Your text is not sent to any server.

Frequently asked questions

Will it change my styles?

No. It changes spacing and line breaks, and may write colours and numbers in a consistent case. Selectors, values and the order of rules stay the same.

Are comments kept?

Yes. Comments stay where they are.

Can it fix invalid CSS?

No. If the CSS cannot be read, for example because of a missing closing brace, you see the line and column of the problem.