CSS Formatter — Pretty-Print and Beautify CSS Online

🔒 Runs in your browser — nothing is sent to a server

CSS formatter that pretty-prints any minified or hand-compressed stylesheet into a clean, readable structure with proper indentation in a single click. Paste a Tailwind purge output, a Bootstrap bundle, an SVG-icon stylesheet or any single-line CSS blob, and this CSS beautifier parses the source, places each declaration on its own line with a configurable 2-space, 4-space or tab indent, splits comma-separated selectors onto their own lines for readable diffs, indents nested at-rules (`@media`, `@supports`, `@keyframes`) and supports modern CSS Nesting. Comments, license `/*! ... */` blocks, CSS variables, vendor prefixes and `!important` are all preserved verbatim. Everything runs 100% inside your browser; your input never leaves your device, nothing is uploaded, logged or sent to any server.

Two-pane view: input and output side by side
Copied!

When to use a CSS formatter online

You reach for a CSS formatter any time a single-line production bundle, a Tailwind purge output, a UI-library theme override or a copy-pasted snippet from DevTools arrives unreadable. Beautifying makes diffs reviewable in code review, lets you scan for a specific declaration without IDE help, and prepares CSS for inclusion in documentation, blog posts or design-system specs. Browser-local formatting matters when the source contains unreleased design tokens, white-label brand colors or internal-only admin themes — the stylesheet never travels to a remote SaaS formatter, never gets logged and never gets cached.

How CSS pretty-printing works under the hood

CSS pretty-printing is a parse-and-render pipeline. A small in-browser tokenizer walks the input character by character, tracking string literals, comments, parenthesised content (`url(...)`, `calc(...)`, `:nth-child(...)`) and brace depth. The tokenizer emits a tree of selectors, declarations and at-rules; comments attach to the next node so they survive into the output. The renderer walks the tree, places each declaration on its own line at the configured indent, splits comma-separated selectors so each lands on its own line for diff-friendly review, indents nested at-rules and CSS Nesting blocks one level deeper than the parent, and inserts a blank line between top-level rules. Identifiers are preserved exactly — vendor prefixes, custom properties, `!important` and license comments all survive untouched. The whole pipeline runs inside the browser engine in milliseconds, even on multi-thousand-line stylesheets.

Examples

Input
.btn{padding:10px;color:#fff;background-color:#2563eb}.btn:hover,.btn:focus{background-color:#1d4ed8}@media (min-width:768px){.btn{padding:14px 20px}}
Output
.btn {
  padding: 10px;
  color: #fff;
  background-color: #2563eb;
}

.btn:hover,
.btn:focus {
  background-color: #1d4ed8;
}

@media (min-width:768px) {
  .btn {
    padding: 14px 20px;
  }
}
CSS formatter — minified production bundle pretty-printed
Input
:root{--brand:#ff8800;--gap:16px}.banner{background:var(--brand) !important;padding:var(--gap);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px)}
Output
:root {
  --brand: #ff8800;
  --gap: 16px;
}

.banner {
  background: var(--brand) !important;
  padding: var(--gap);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
Pretty print CSS — :root tokens with var() and !important
Input
.css-formatter{content:"css formatter";font-family:"Inter",sans-serif;color:#112233;padding:.5rem}
Output
.css-formatter {
  content: "css formatter";
  font-family: "Inter", sans-serif;
  color: #112233;
  padding: .5rem;
}
Format CSS online — payload that names the tool itself
Input
.card{padding:12px;border:1px solid #ccc;&:hover{border-color:#888}& .title{font-size:1.25rem}}
Output
.card {
  padding: 12px;
  border: 1px solid #ccc;

  &:hover {
    border-color: #888;
  }
  & .title {
    font-size: 1.25rem;
  }
}
CSS beautifier — modern CSS Nesting expanded with extra indent

FAQ

How do I beautify a minified CSS stylesheet?

Paste the minified or single-line CSS into the input above and click Beautify. The CSS formatter parses the source with a small in-browser tokenizer, places each declaration on its own line with a 2-space indent by default, and puts the closing `}` on its own line. Comma-separated selectors land on separate lines for readable diffs unless you turn that off.

What is CSS beautifying or pretty-printing?

CSS beautifying — also called pretty-printing — reformats compact CSS by inserting line breaks, indentation and spacing so a human can read and edit the file. The cascade is unchanged: the same selectors, the same declarations, the same specificity, just laid out for visual scanning. Most CSS pretty printers default to two-space indentation, the convention adopted by Prettier and most style guides.

What indentation does this CSS pretty printer use?

Two spaces by default — the convention used by Prettier, Stylelint and most modern style guides. The Indent size selector also offers four spaces and tab indents for teams that prefer them. Two-space indentation is dense enough to keep deeply nested at-rules and CSS Nesting blocks on screen, while still distinguishing every level visually.

How does the CSS formatter handle @media, @keyframes and CSS Nesting?

Nested at-rules — `@media`, `@supports`, `@container`, `@keyframes` and `@layer` — keep their structure: their inner rules get one extra level of indent. CSS Nesting blocks (`&:hover`, `& .title` written inside a parent rule) are detected and pretty-printed with the same indent rule. Declaration-only at-rules like `@font-face` and `@page` format as a single declaration block.

Does the CSS beautifier preserve `!important`, CSS variables and vendor prefixes?

Yes. `!important`, CSS custom properties (`--brand`, `--gap`), `var(...)` references and vendor prefixes (`-webkit-`, `-moz-`, `-ms-`, `-o-`) are kept exactly as written. The formatter never renames identifiers, never alters the cascade and never strips browser-engine prefixes — those decisions belong to the build pipeline (autoprefixer, postcss), not to a pretty printer.

How is CSS beautify different from CSS minify?

CSS beautify and CSS minify are exact opposites. Beautify adds line breaks and indentation to make the stylesheet easy to read and diff. Minify strips every byte that is not strictly needed, producing the smallest valid CSS for transport. The cascade is identical in both directions; only cosmetic whitespace and comment retention differ. Use beautify for review, minify for deploy.

Can I sort CSS properties alphabetically?

Yes — toggle "Sort properties alphabetically" in Options. It produces stable diffs and is helpful in code review, but it breaks logical groupings that many style guides recommend (display → position → box → typography → color). Leave it off if you follow Smacss, Idiomatic CSS or a similar guide; turn it on for diff-friendly machine-managed stylesheets.

Is it safe to paste a proprietary stylesheet into this CSS formatter online?

Yes — the CSS beautifier runs entirely in your browser using a tokenizer written in plain TypeScript. Your stylesheet and the formatted output stay on your machine; nothing is uploaded, logged or cached. Safe for unreleased design tokens, white-label brand themes, internal admin styles and any CSS you would not want a remote SaaS formatter to retain.

Glossary

CSS (Cascading Style Sheets)

CSS is the W3C-standard language for describing the presentation of HTML and SVG documents — colors, layout, typography, motion. A CSS formatter reformats a stylesheet without changing how the browser renders the page. The parsed cascade is identical before and after pretty-printing; only the whitespace, line breaks and indentation a human sees in the source change.

CSS beautifier

A CSS beautifier is any tool or function that takes a stylesheet and emits it with controlled indentation, line breaks and spacing. Prettier, Stylelint --fix, the VS Code "Format Document" command and `cssbeautify` on npm are all CSS beautifiers. Browser-local CSS beautifiers like this page have a privacy advantage: the source never leaves the tab, so unreleased design tokens stay on the developer machine.

CSS Nesting

CSS Nesting is the official W3C module that lets you nest rules inside other rules, as Sass and Less have for years. `&:hover { color: blue }` inside `.btn { ... }` reads as "when `.btn` is hovered". Browsers shipped support across 2023–2024. A modern CSS pretty printer must detect nested rules and indent them one level deeper than the parent.

At-rule

An at-rule is any CSS statement that starts with `@` — `@media`, `@supports`, `@keyframes`, `@import`, `@layer`, `@font-face`. Some at-rules wrap a block of nested rules (`@media`, `@supports`); some hold a declaration block (`@font-face`, `@page`); some are single statements (`@import`, `@charset`). A correct CSS beautifier prints each form differently and indents the nested ones.

CSS custom property (CSS variable)

A CSS custom property — written as `--brand`, `--gap`, `--radius` — is a user-defined value declared inside a selector and read with `var(--name)`. Custom properties cascade and inherit like any other CSS value. A pretty printer must never rename, remove or rewrite a custom property or its `var()` reference because external JavaScript may write or read them by name at runtime.

License comment

A license comment is a CSS comment that opens with `/*!` instead of `/*` — for example `/*! Bootstrap v5.3.2 | MIT License */`. The `!` marker is the convention shared by every major CSS minifier and beautifier (cssnano, terser, UglifyCSS) for "preserve this comment". A correct CSS formatter keeps every license comment intact even when the user asks to strip ordinary comments.

Related tools