ToolsHub4u

Indent minified or messy CSS

Paste compact CSS and get one declaration per line, with indented blocks and a blank line between rules. Comments can be kept or removed.

  • One rule per line
  • Strings preserved
  • Runs locally
Ready Developer & Utility
1Enter
2Adjust
3Copy result

CSS Beautifier

1

CSS input

No data yet Live
2

Beautified CSS

Formatted 21 lines of CSS.

Beautified CSS

  • Strings and comments were tokenisedA semicolon or brace inside a quoted string or comment did not end the declaration.
  • Property spacing is normalisedThe first colon in a declaration gets one space after it. Custom properties and values containing colons keep the rest of their text.
Input characters
232
Output characters
300
Lines
21
Rule blocks
5

This is a whitespace formatter for CSS-like syntax. It does not validate the stylesheet, resolve nesting or understand preprocessor syntax such as SCSS variables and mixins.

This page takes compact or badly spaced CSS and writes it back with one declaration per line, indented rule blocks and a blank line between top-level rules. Paste a stylesheet, choose two spaces, four spaces or a tab, and the output appears beside the form. Comments can be kept or removed with a checkbox.

It is a formatter, not a validator. It does not check property names, resolve custom properties or tell you that a selector is invalid. Its job is to make the structure visible so a human can review it, and to turn a minified file back into something readable.

What changes in the output

Each rule is written as a selector line, an opening brace, one declaration per line and a closing brace. Declarations keep their property and value text; the formatter adds a colon and a space where needed and a semicolon at the end of each line. Nested blocks such as a media query are indented one level deeper than the rule that contains them.

The output is longer than the input because it adds line breaks and indentation. That is expected. The character count in the stats will rise even when the CSS is already valid and well spaced, so do not read the increase as a problem.

At-rules are kept in place. A @media block is written with its query on the same line as the at-keyword, and the rules inside it are indented. The formatter does not rewrite the query, add spaces around the colon in (max-width:600px), or normalise a font stack such as system-ui,sans-serif. Those are value-level changes, and it deliberately leaves values alone.

Indentation and comments

The indent control offers two spaces, four spaces or a tab. Two spaces is the common choice for CSS because it keeps deeply nested media queries readable without pushing rules far to the right. A tab is compact on screen but renders at different widths in different editors, so agree with the rest of the project before using it.

Comments are kept by default. Clearing the checkbox removes both standalone comments and inline comments such as /* inline */ at the end of a declaration. That is useful before pasting a stylesheet into a size-sensitive build, but it also removes licence headers and source-map hints. Keep a copy of the original if those matter.

The formatter does not add comments, reorder declarations, merge duplicate selectors or remove unused rules. Two rules with the same selector stay two rules, in the order they appeared. If you need dead-code removal or selector merging, that is a build-step job with a real parser, not a text formatter.

A worked example

A 232-character stylesheet with a custom-property block, a body rule, a card rule and a media query was pasted with two-space indentation. The page reported 21 lines, 5 rule blocks and 300 output characters.

Three formatting runs and their measurements
InputSettingResult
Four-rule stylesheet, 232 characters2 spaces, comments kept21 lines, 5 blocks, 300 characters
a{color:red;margin:0}Tab, comments kept4 lines, 30 characters
Rule with two comments, 56 characters2 spaces, comments removed4 lines, 37 characters

The tab run is the smallest useful check: the selector, two declarations and the closing brace each end up on their own line, with a tab before each declaration. The comment-removal run dropped both the leading comment and the inline one, leaving the rule itself unchanged.

In the larger run the media query stayed at the end and its inner rule gained a second level of indentation. The output is valid CSS as long as the input was valid; the formatter does not repair an unclosed brace or a missing colon.

Format before you diffA formatter changes whitespace on almost every line. If you are comparing two versions with the code diff checker, format both with the same settings first, or the diff will be mostly indentation noise.

Strings, custom properties and edge cases

Values are copied as text, so a quoted font name or a data URI keeps its punctuation. Custom properties such as --ink: #1c1b18; are formatted like any other declaration. The formatter does not try to parse the value, which is why it will not break a calc() expression or a url() containing a semicolon.

An empty input produces an empty result rather than an error. A file with only comments and no rules is formatted as comments, and the rule-block count is zero. Very large stylesheets are processed as text in the tab; there is no server round trip, so the practical limit is the browser's patience rather than a quota.

When to beautify and when to minify

Beautify when you are reading, reviewing or debugging. Minify when you are shipping, because whitespace and comments are bytes the browser does not need. The two operations are opposites, and a round trip through both should return the same rules even though the text will not be byte-identical.

This page is the readable direction. The CSS minifier is the other one. If you are formatting HTML that contains a style block, use the HTML beautifier instead; it treats the style block as text and does not format the CSS inside it.

Questions

Common questions

Short answers about this tool and its limits.

Does the beautifier validate my CSS?

No. It formats the text and does not check property names, values or selector syntax. A missing brace or colon may produce odd indentation rather than an error, so run a validator separately if correctness matters.

Why did the output get longer?

Because the formatter adds line breaks, indentation and spaces around declarations. That is the point of beautifying. The character count rises even when the CSS was already valid.

Does it change the order of my rules?

No. Rules stay in source order, and duplicate selectors are not merged. The cascade therefore behaves the same as before, as long as the input was valid.

Can I remove all comments?

Yes. Clear the comments checkbox. Both standalone and inline comments are removed. Licence headers and source-map hints go too, so keep the original file if you need them.

Does it format CSS inside a style tag?

Not when you paste HTML. The HTML beautifier treats a style block as text. Paste the CSS itself into this page, or format the two parts separately.

Can I use tabs instead of spaces?

Yes. The indent control has a tab option. Agree on the setting with the project, because tabs render at different widths in different editors and can make a shared file look inconsistent.

Does it support nested CSS?

It indents by braces, so a nested rule is written one level deeper. It does not parse nesting semantics or check that the nesting is valid for the browser. Treat the output as formatted text.

Is my stylesheet uploaded?

No. Formatting runs in the browser. There is no account, no history and no server copy, and the download is created locally as a text file.