Guide

Formatting CSS: beautify to edit, minify to ship

Reviewed 23 November 2026 · 5 min read · Written and maintained by Toolnexo

Stylesheets reach you in two shapes. The one you write is spread over many lines. The one a build tool ships is squeezed onto a single line to save bytes. Sooner or later you need to read the squeezed version, or make a messy file consistent before a review. This guide explains what a CSS formatter does, what it leaves alone, and how it relates to minifying. The examples come from the CSS formatter on this site, which runs in your browser, so your code is not uploaded.

What a formatter changes

A formatter changes whitespace and nothing else. It puts each declaration on its own line, indents the contents of every block, puts a space after each colon and comma, and puts a space around selector combinators such as > and +. For example, .card,.panel>.title{margin:0 auto;padding:8px 16px} becomes four lines with the two selectors on separate lines and the declarations indented under them.

Browsers ignore this whitespace, so the page looks exactly the same. The purpose is for people: a reviewer can see which declaration changed, and a diff shows one line per change instead of one huge line.

What it must never change

  • Strings: a semicolon, brace or comma inside quotes is content, so content: "; }" has to stay as written.
  • url(...) values: a data URL can contain semicolons and commas that must not be touched.
  • Comments: they are kept exactly, on their own line at the current indent.
  • Values: the formatter does not reorder properties, change colours, remove prefixes or fix mistakes. It reads structure, not meaning.
  • Spacing around operators: inside calc() the + and − operators need surrounding spaces to be valid, so the formatter never removes them.

Indent, selector and blank-line choices

Two spaces, four spaces and tabs are all valid, and the right one is whatever your project already uses, since a mixed file produces noisy diffs. Putting one selector per line makes a long list such as h1, h2, h3, h4 easier to scan and to edit. A blank line between top-level rules separates them visually but makes the file longer, so teams differ on it, and the tool lets you switch it off.

Nested rules and at-rules such as @media, @supports and @layer are indented one level deeper, so the structure is visible at a glance. Top-level @charset and @import lines are kept together at the top without a blank line after each.

A real example of the size change

The tool's built-in sample is a short stylesheet of 323 bytes with 7 rules and 12 declarations. Formatted with two spaces and blank lines, it becomes 415 bytes, which is 92 bytes of added spacing (with four spaces of indent it is 451 bytes). That is the cost of readability, and it is why you format for editing and minify for delivery.

Format to read, minify to ship

Formatting and minifying are opposites. A formatter adds line breaks and indentation so people can read the code. The CSS minifier removes comments and whitespace so the file is smaller to send. A good workflow keeps the formatted source in your repository, minifies it during the build, and uses a formatter whenever you have to inspect a minified file from a live site.

Two limits to remember. The formatter targets plain CSS and native nesting, so SCSS and Less features such as mixins or dollar-sign variables are not understood. And unbalanced braces or unterminated strings are reported as warnings, because formatting a broken file cannot make it correct.

Tools in this guide

Put it into practice

How this guide is maintained

This page is reviewed when the related tools change. It describes what the published tools actually do: the tools run in your browser tab, so your files stay on your device. If you find something inaccurate, email [email protected] and it will be corrected.

Keep reading

Other guides

All guides →