ToolBook
Support us on Ko-fi
Help us keep this free, forever

CSS Formatter / Minifier

How to use CSS Formatter / Minifier

Beautify CSS for readability or minify it for production in five steps.

  1. Paste your CSS

    Paste any CSS, a single rule, a full stylesheet, or output from a build tool, into the input panel.

  2. Choose an indent style or Minify

    Select 2 spaces, 4 spaces, or Tab to beautify. Choose Minify to strip all whitespace and comments for production.

  3. Optionally sort properties A-Z

    Toggle Sort A-Z to reorder property declarations alphabetically within each rule for a consistent, scannable stylesheet.

  4. Check the stats

    The stats bar shows rule count, property count, and the original vs output byte sizes so you can see the exact savings.

  5. Copy or download

    Click Copy to clipboard or Download to save the result as a .css file.

Frequently asked questions

What does the CSS formatter do?

The formatter parses your CSS and rewrites it with consistent indentation, one property per line, and one blank line between rules. The minifier does the opposite: it removes all comments and non-essential whitespace to produce the smallest possible file.

Does the minifier remove comments?

Yes. All CSS comments (/* ... */) are stripped during minification. If you have license comments or directives you need to preserve, wrap them in a /*! */ block before minifying (the tool treats /*! as a preserved comment).

How much does CSS minification save?

Minification alone typically saves 20-30% for average stylesheets. Combining with HTTP gzip compression usually achieves 70-80% reduction from the original formatted file. The tool shows the exact before-and-after byte counts so you can see the real gain.

What does Sort A-Z do, and when should I use it?

Sort A-Z reorders property declarations alphabetically within each rule block. It makes large stylesheets easier to scan and helps teams enforce a consistent property order. Note: if your CSS relies on declaration order for cascade overrides (for example, "background: red" followed by "background-color: blue"), sorting will change that behavior. Leave Sort A-Z off if order matters.

Does the formatter handle nested CSS (like Sass or SCSS)?

No, the formatter handles standard CSS. Nested selectors (used in Sass, SCSS, and native CSS nesting in modern browsers) are not supported. For preprocessor syntax, run Sass compilation first, then format the output.

Will formatting change how my CSS behaves in the browser?

No. Formatting only affects whitespace and indentation, which the browser ignores. Minification removes comments and redundant whitespace but preserves every declaration. The only feature that can affect rendering is Sort A-Z: if your CSS depends on property declaration order for cascading, sorting will change the output.

Does it work with CSS custom properties (variables)?

Yes. Custom properties like "--primary-color: #ee7a2b" are treated as regular declarations and format correctly. Values that reference var() also format correctly regardless of nesting depth.

Is my CSS sent to a server?

No. All formatting and minification runs entirely in your browser using JavaScript. Your stylesheet never leaves your device.

Can I use this for Tailwind or utility-class CSS output?

Yes. Tailwind generates standard CSS output. Paste the compiled stylesheet from your build tool and the formatter will indent it for inspection. The minifier can also compress utility class output.

CSS formatting and minification: a developer's guide

Consistent indentation for development, maximum compression for production — and how minification interacts with gzip.

Why CSS formatting matters

CSS written by hand develops inconsistent indentation, mixed spacing around colons, selectors split across lines, and properties in no particular order. CSS generated by preprocessors, build tools, or AI-generated code is often either unformatted (one long line) or using a different convention than the rest of your stylesheet. Consistent formatting makes diffs smaller, code reviews faster, and onboarding easier.

Minification is the production-time counterpart: maximum compression for the fastest possible delivery.

What the formatter does

The formatter processes CSS as a flat character stream, tracking:

  • Nesting depth: Each { increases the indent level, each } decreases it. This handles media queries, @supports, @keyframes, and other at-rules with nested blocks.
  • Property lines: Content between { and } that ends with ; is treated as a property declaration and placed on its own indented line.
  • Strings: Content inside '...' or "..." is not split or reformatted, protecting URLs, font names, and content values.
  • Functions: Content inside (...) is kept intact, protecting calc(), color-mix(), var(), and custom property references.
  • Comments: /* ... */ comments are preserved in formatted output and stripped in minified output.

What minification does

CSS minification applies a series of safe transformations:

  1. Strip all /* ... */ comments (configurable — /*! preserved comments are a common extension but not implemented here).
  2. Collapse consecutive whitespace to a single space.
  3. Remove whitespace around {, }, ;, :, and ,.
  4. Remove the last semicolon before } (redundant in CSS).

The result is syntactically identical — any CSS parser, browser engine, or PostCSS plugin will produce the same cascade from the minified stylesheet as from the formatted version.

Minification + gzip: the real numbers

CSS minification alone typically saves 20–30% by removing comments and whitespace. But CSS bytes are highly repetitive — property names and values repeat across rules — which makes gzip extremely effective. The combined savings from minification + gzip compression (which all modern HTTP servers apply automatically) typically produce 70–85% reduction from the original formatted source.

For a 50 KB formatted stylesheet:

  • Minified alone: ~35 KB
  • Original + gzip: ~12 KB
  • Minified + gzip: ~9 KB

The 3 KB difference matters at scale (millions of pageviews) but is invisible for small sites. Still, minification is free in any build pipeline that uses PostCSS or Webpack, so there's no reason not to.

CSS nesting: what's supported

The formatter handles standard CSS nesting as encountered in build tool output (Tailwind, PostCSS nesting plugin, compiled Sass). It does not handle native CSS nesting syntax (where selectors nest using &) — that feature is part of CSS Nesting Level 1, currently in limited browser support. For native nesting syntax, the formatter may produce unexpected indentation.

For SCSS or Sass source files, run the Sass compiler first to produce standard CSS, then format the output.

At-rules

The formatter handles all standard at-rules:

  • @media, @supports, @layer, @container: block at-rules that contain nested rules, formatted with indentation.
  • @import, @charset, @namespace: statement at-rules that end with ;, formatted as single lines.
  • @keyframes: block at-rule with nested stop rules (0%, 100%, etc.), indented correctly.
  • @font-face: treated as a regular rule block with properties.