/

CSS Beautifier / Minifier

Processed Client Side

Format messy or minified CSS into readable, indented rules — or minify a stylesheet down to one line. Runs entirely in your browser.

Input · 6 lines · 584 chars
CSSLength: 584Lines: 6Size: 586 BytesCursor: 1:1
Output
Beautified
CSSLength: 699Lines: 30Size: 701 BytesCursor: 1:1
5 rules6 selectors15 declarations2 custom properties1 media query1 comment1 !important

Bookmark this tool now — skip the search next time you need it.

About CSS Beautifier / Minifier

This tool runs entirely in your browser. Whatever you paste is processed on your own device and is never uploaded, logged, or sent to any server.

The CSS Beautifier does the two things you need when a stylesheet is unreadable: expand it, or squeeze it. Beautify takes CSS that arrived as one enormous line — out of a build, a page inspector, or a theme you bought — and rebuilds it into indented rules, one declaration per line, with each selector in a list on its own line when the list gets long. Minify runs the other way, collapsing a stylesheet down to a single line and dropping every comment except the licence header. Neither mode works by regex over the text: the CSS is parsed into rules, declarations, at-rules and comments first, which is why a semicolon inside `content: ";}"` and a comma inside `url(data:image/png;base64,…)` come out the other side intact. Everything happens in your browser, so an unreleased stylesheet is never uploaded anywhere.

Key features

  • Beautify and minify from one toggle, with the output re-running on every keystroke
  • A real parser rather than find-and-replace — strings, comments and unquoted url() values are recognised and passed through character for character
  • Indentation of 2 spaces, 4 spaces or tabs, and an Expanded or one-rule-per-line layout
  • Selector lists split one per line automatically when they pass 80 columns, or always, or never — your choice
  • Long multi-part values — box-shadow stacks, transition lists, gradients, font stacks — wrap one part per line instead of running off the edge, and grid-template-areas prints one row string per line so the grid is drawn in the source
  • Modern CSS understood: nesting with &, @media, @supports, @container, @layer, @keyframes, @font-face and custom properties, which keep their value exactly as written because a --variable holds an arbitrary token stream rather than a CSS value
  • Comments preserved when beautifying, including a comment that trailed a declaration — it goes back onto that same line
  • Minify keeps bang comments, because that is where the licence header lives
  • Optional value shortening on minify: hex colours folded to lower case and to three digits, redundant zeros trimmed, zero lengths reduced to 0, and empty rules dropped
  • Tolerant of broken input — an unclosed block, a stray brace or a half-typed rule still formats, and is reported as a warning rather than an error
  • A statistics row counting rules, selectors, declarations, custom properties, media queries, comments and !important declarations
  • Syntax highlighting in both panes, plus copy to clipboard and download as a .css or .min.css file
  • Runs entirely in your browser — nothing you paste is uploaded

How to use it

  1. Paste your CSS into the left pane, replacing the sample.
  2. Pick Beautify to expand the stylesheet, or Minify to collapse it.
  3. For Beautify, choose the indentation, whether rules are Expanded or kept to one line each, how selector lists should break, and what to do with blank lines.
  4. For Minify, choose Full to also shorten colours and zeros, or Safe if you want whitespace and comments removed and nothing else touched.
  5. Read the result on the right — it re-runs as you type — and check the badges underneath for the rule counts and any warnings.
  6. Copy the output, or download it as a .css or .min.css file.

Tips & common mistakes

  • Minify reports the size saving as a percentage next to the output. It is measured against the text you pasted, so beautified input will always show a bigger number than input that was already compact — compare against your build output, not against the sample.
  • Safe minify removes only whitespace and comments. Full minify additionally lower-cases and shortens hex colours, trims redundant zeros, drops units from zero lengths, and removes rules whose body is empty. If you are minifying someone else’s stylesheet and want to be able to diff the result, use Safe.
  • Zero lengths lose their unit; zero times, angles and percentages keep theirs. `margin: 0px` is the same as `margin: 0`, but `transition-duration: 0` is invalid where `0s` is fine, and `rotate(0)` means something different from `rotate(0deg)`.
  • The contents of calc(), min(), max() and clamp() are never touched. Those functions type-check their arguments, so `calc(0px + 1em)` has to keep the unit — `calc(0 + 1em)` is not valid CSS.
  • Nothing is merged or reordered. Two rules with the same selector stay two rules, and a property declared three times keeps all three declarations, because whether a duplicate is dead or a deliberate fallback for an older browser depends on the page — which a formatter cannot see.
  • Custom property values are passed through exactly as written, whitespace aside. The value of a --variable is a token stream that only means something when var() puts it somewhere, so re-spacing it would be guesswork.
  • A comment starting with a bang survives minification. Put your licence header in one — losing it during a build is a licensing problem, not a cosmetic one.
  • This is a formatter, not a linter: unknown properties, misspelled units and half-typed rules all format without complaint. The output is still a useful hint, though — a block that indents somewhere you did not expect usually marks a brace you forgot to close, and unclosed blocks and unterminated strings are flagged as warnings.
  • Use "One rule per line" to scan a large stylesheet. It gives every rule a single line, which makes an overview of a few hundred selectors readable in a way that a fully expanded file is not.
  • The !important badge counts how many declarations use it. It is worth a look on inherited CSS — a specificity war is much easier to see as a number than by scrolling.

Related tools

Browse all 10 Code tools

Frequently asked questions

10

Paste the stylesheet into the left pane and the formatted version appears on the right immediately, updating as you type. Choose 2 spaces, 4 spaces or tabs for indentation, then copy the result or download it as a .css file. Nothing is uploaded — the formatting runs in your browser.

Yes, that is the main thing Beautify is for. A minified stylesheet is parsed into its rules and declarations and printed back out with one declaration per line and one level of indent per block, including inside media queries and nested rules. What it cannot restore is the comments and the original property order, because a minifier already removed the first and never changed the second.

It makes the file smaller, which is not quite the same thing. Minified CSS transfers fewer bytes and parses marginally sooner, but the win is modest once gzip or brotli compression is in play — compression already handles repeated whitespace well. Treat it as a cheap improvement to ship rather than a fix for a slow page.

On Safe, only whitespace and comments — with bang comments kept, since that is where licence headers live. On Full it also lower-cases hex colours and shortens them where the digits repeat, trims redundant zeros, drops the unit from zero lengths, and removes rules with an empty body. In both modes your declarations, their order and their values are otherwise left alone.

It should not, and the awkward cases are handled deliberately. Strings are never edited, so `content: ";}"` survives; unquoted url() values are passed through whole, so a data URI keeps its commas; the contents of calc() and friends are untouched, so `calc(0px + 1em)` keeps a unit it needs; and zero times and angles keep theirs. Nothing is merged or reordered either, so a fallback declaration for an older browser cannot be optimised away.

Yes. Nested rules and & selectors indent like any other block, and @media, @supports, @container, @layer, @keyframes, @font-face and @property are all understood, including when nested inside a rule. Custom properties are kept exactly as written, because the value of a --variable is an arbitrary token stream rather than a normal CSS value.

When beautifying, yes — a comment above a rule stays above it at the same indentation, and a comment that trailed a declaration goes back onto that declaration’s line. Minifying removes them, except a comment starting with a bang, which is kept in both modes so a licence header cannot be lost in a build.

Because the declaration went past 80 characters and its value has more than one comma-separated part. Shadows, transitions, gradients and font stacks read far better one part per line than wrapped at the window edge. grid-template-areas is broken the same way, one row string per line, so the grid is visible in the source.

No — it formats rather than validates, which is what you want when the stylesheet is half-written. Unknown properties and misspelled units format like anything else. Structural problems are surfaced as warnings, though: an unclosed block, a stray closing brace or an unterminated string are all reported next to the output, and the input still formats.

No. The parser and both printers are JavaScript running in your browser tab, and there is no request that sends a stylesheet anywhere. That is what makes it safe to paste CSS from an unreleased design, a client project, or an internal application.