format.CoShareX
HomeBlogFormattersHow to Format CSS
Formatters

How to Format CSS

Published 2026-08-10
3 min read
By CoShareX

CSS (Cascading Style Sheets) controls the styling and layout of web pages. As selectors, media queries, and properties accumulate, stylesheets can quickly become difficult to read. Clean formatting keeps your CSS code organized.

In this guide, we'll explain how to format and organize your CSS files.

Selector and Property Formatting

Standard formatting rules recommend:

  • Placing a space before the opening brace ({).
  • Writing each property declaration on its own line.
  • Indenting property declarations (typically with 2 spaces).
  • Placing a semicolon after every property declaration.

Unformatted CSS:

css
1
.card{background:#fff;border:1px solid #ccc;border-radius:8px;}

Formatted CSS:

css
1
2
3
4
5
.card {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
}
Featured Tool

CSS Formatter

Format, tidy and indent CSS stylesheets.

Property Ordering Guidelines

Grouping related CSS properties together makes them easier to read:

  1. Layout: display, position, grid, flex, margin, padding
  2. Size: width, height
  3. Typography: font-family, font-size, text-align
  4. Visuals: background, border, opacity