What is a CSS formatter?
A CSS formatter takes compressed or messy stylesheet code and prints it out neatly: one rule per block, one declaration per line, and indentation that shows which declarations belong to which selector. The CSS does exactly the same thing after formatting — browsers do not care about spacing — but humans care a great deal, because readable CSS is editable CSS.
The need comes up constantly. Stylesheets copied from a live website arrive minified, with everything on one line. Code pasted from a tutorial arrives with random indentation. A stylesheet edited in a hurry ends up with three different indent styles in one file. A formatter takes any of those and returns one consistent layout in a single click.
The default example on this page is a typical case. Two rules, body and h1, written with no spaces at all: body{margin:0;padding:0}h1{color:#333;font-size:24px}. The formatter turns that into 8 lines, with each declaration on its own line and a closing brace that lines up with its selector. Nothing about the styling changes — the page looks identical.
Formatting is not the same as fixing CSS. A formatter does not check whether your properties are valid, does not warn you about a typo in a property name, and does not change which rules win when two selectors conflict. It only changes the layout of the text. That is a smaller job, but it is the job that makes all the other jobs possible, because you cannot fix what you cannot read.
How this CSS formatter works
The formatter walks through the CSS character by character, watching for the three characters that define its structure: the opening brace, the closing brace, and the semicolon. An opening brace starts a new block, so the selector goes on its own line and the indentation level goes up by one. A semicolon ends a declaration, so the declaration gets its own line at the current level. A closing brace ends the block, so the level drops and the brace goes on its own line.
Strings inside the CSS are protected while this happens. A value like content: "}"; contains a brace that is not a block boundary, and the formatter tracks quotes so it is never mistaken for one. The same applies to URLs in background-image values and to font names with spaces in them — the formatter reads them as text, not as structure.
Nested rules work the same way, one level at a time. A media query wraps other rules inside it, so the rules inside are indented one extra level. Take @media screen and (max-width:600px){.box{display:none}} with 4-space indentation: the media query opens at level zero, the .box rule sits at one level, and its declaration sits at two levels — 5 lines in total, and the nesting is visible at a glance.
The indentation selector changes only the spacing character, not the structure. Two spaces is the most common choice and the default. Four spaces suits people who want deeper visual nesting, and tabs suit editors configured for tab indentation. The line count and the rule count stay the same whichever you pick; only the leading whitespace changes.
The numbers: lines, rules, and length
The three numbers above the output describe the formatted result. Lines is the count of lines in the formatted CSS — 8 for the default example, which has two rules with two declarations each. Rules is the count of opening braces in the input, which is the number of rule blocks: 2 in the default, one for body and one for h1. Output length is the character count of the formatted text.
Those numbers are a quick sanity check. If you paste a stylesheet and the rule count is far lower than you expected, a brace is probably missing somewhere and two rules have merged into one. If the line count is much higher than the rule count suggests, the file may have many declarations per rule, which is normal for a large stylesheet. A stylesheet with 50 rules and 200 declarations formats to roughly 250 lines, and the numbers tell you that before you scroll.
The output is usually longer than the input, and that is the point. The default example is 54 characters of compressed CSS, and the formatted version is 72 characters — longer, because it adds newlines, spaces, and a semicolon after the last declaration of each rule. Formatting trades bytes for readability, and that trade is worth it every time a human has to read the file.
When you are done editing, the flow goes the other way: format to read and edit, then minify to ship. The two tools are a pair, and the numbers help at both ends — the formatter's line count tells you how much there is to read, and a minifier's character count tells you how much will actually be sent to visitors.
A worked example: two rules, eight lines
Start with the default CSS: body{margin:0;padding:0}h1{color:#333;font-size:24px}. It is 54 characters, two rules, and no whitespace at all. Paste it in and the formatter reads the first selector, body, and the opening brace, and writes body { on its own line.
Inside the body block, the declarations split at each semicolon. margin:0; goes on the first indented line, padding:0; on the second — and note the semicolon: the formatter adds one after the last declaration in a rule even when the input omits it, so padding:0 becomes padding:0;. The closing brace drops back to the left margin.
The h1 rule follows the same pattern: h1 { on its own line, then color:#333; and font-size:24px; indented by two spaces, then the closing brace. The whole result is 8 lines and 72 characters, and a browser given either version renders the page identically — same margins, same colour, same font size.
Try the media query example to see nesting: @media screen and (max-width:600px){.box{display:none}}. With 4-space indentation it formats to 5 lines and 2 rules, with the .box rule indented once and its declaration indented twice. That nesting is exactly what makes a long stylesheet with several media queries possible to follow.
Who formats CSS, and when
Front-end developers format CSS whenever they inherit a stylesheet they did not write. A theme bought from a marketplace, a stylesheet copied from another project, or CSS generated by a design tool all arrive in someone else's layout. Formatting it first means the developer reads the code in a consistent style from the start, instead of fighting the original author's habits.
It is also the first step in debugging a layout. When a page looks wrong, the cause is usually one rule overriding another, or a declaration in the wrong block. Neither is visible in a minified file where everything sits on one line. Formatted, the structure is obvious: which declarations belong to which selector, and which selectors sit inside which media query.
Students learning CSS use a formatter to check their own work. Writing CSS by hand in a plain editor is easy to get wrong — a missing brace, a declaration outside any rule — and a formatted view makes the mistake visible. If the indentation looks wrong, the structure is wrong, and that is a far quicker diagnosis than staring at a single long line.
Content teams that paste CSS into a page builder or a blog template use a formatter to keep the snippet tidy. A short block of custom CSS in a page is usually written once and forgotten, and the next person to touch it will be grateful if it is laid out cleanly. Formatting takes seconds and pays off the first time anyone opens the file again.
CSS formatter vs other text tools
A CSS formatter is a specialist: it understands braces, semicolons, and nesting, and nothing else. A general text formatter that only fixes indentation would not know where a rule ends, and a code editor's auto-indent does the same job but only inside that editor. This page does it for any CSS you paste, with no editor and no setup.
The closest relative is the JS formatter in this same group, which does the same job for JavaScript: braces open blocks, semicolons end statements, and indentation shows the nesting. The two tools share the same idea — structure made visible through layout — but each knows the grammar of its own language, so neither is a substitute for the other.
For data rather than code, the JSON formatter does the equivalent job: it takes compressed JSON and prints it with indentation so the structure is visible. And for plain prose, a text formatter tidies spacing and line breaks without understanding any grammar at all. Each tool matches the structure of what it formats. When the CSS sits inside a page, an HTML encoder handles the angle brackets safely, and a Markdown editor is the place to draft the documentation that explains what the stylesheet does.
The formatter also pairs with a minifier in the opposite direction. Format to read and edit, minify to ship. A stylesheet that is formatted for development and minified for production gets the best of both: humans read the clean version, visitors download the small one, and neither version is a compromise.
Common CSS formatting mistakes
The first mistake is formatting CSS that has a syntax error and expecting the formatter to fix it. A missing closing brace makes everything after it look like it belongs inside the unclosed rule, so the indentation goes wrong from that point on. The formatter shows the structure as written, including the error — which is actually useful, because the point where the indentation goes wrong is usually where the brace is missing.
Second: treating formatted output as proof the CSS is valid. Formatting only changes layout. A property spelled colr instead of color formats perfectly and still does nothing in a browser. A selector that matches nothing formats perfectly too. Use the formatter to read the code, then check the result in a browser to see whether it actually works.
Third: mixing indent styles by hand after formatting. The whole point of a formatter is one consistent style. If you edit the formatted output and add a rule indented with tabs while the rest uses two spaces, the file drifts back into the mess you started with. Pick one indent style, set your editor to match it, and reformat after edits.
Fourth: forgetting that some CSS is not standard CSS. Preprocessor code with variables, nesting written in the Sass style, or custom at-rules may not follow the brace-and-semicolon pattern this formatter expects. This tool is a formatter for standard CSS, and it says so in the formula line — preprocessor files deserve their own tools.
How to use this CSS formatter
Paste your CSS into the box at the top. The default example is already there: two compressed rules that format into 8 lines. Replace it with your own stylesheet and the formatted result appears instantly, with no button to press and no waiting.
Choose your indentation from the dropdown. Two spaces is the default and the most widely used style. Four spaces gives deeper nesting that some people find easier to scan, and tabs match editors configured for tab indentation. Switching the option reformats the same CSS immediately, so you can compare styles before you copy.
Copy the formatted CSS from the output box and paste it into your stylesheet or editor. Check the line and rule counts first: if the rule count looks wrong, scroll through the output and look for the place where the indentation stops making sense — that is usually where a brace is missing in the input.
Everything runs in your browser. Your CSS never leaves your device, is never uploaded, and is never stored. You can format proprietary stylesheets, half-finished drafts, or client work without worrying about where the code goes — it goes nowhere, and closing the page removes it. Formatted stylesheets belong in version control — but not the build output; our gitignore generator writes the ignore rules for your stack.