Skip to content

Menu

CSS Formatter

Format, beautify, and minify CSS with indent options.

Runs entirely in your browserFormattersFree, no sign-up
Loading tool

01What is CSS Formatter?

Minified CSS from a production bundle is close to unreadable. One long line, no indentation, and a selector you need buried somewhere around character 40,000. The CSS Formatter turns that back into something you can scan, and it can also go the other way and squash readable CSS down. You paste a stylesheet into Input CSS, pick Beautify or Minify, and press Format. Under the hood the text is split into tokens before anything is rewritten. Quoted strings, comments and unquoted url() values each become a single unit. That matters more than it sounds. A data URI such as url(data:image/png;base64,...) contains semicolons, and a naive formatter would break the line right in the middle of it. Here it stays intact. Beautify puts every declaration on its own line, indented by 2 or 4 spaces. It adds a space after the property colon and makes sure the last declaration ends with a semicolon. Comma-separated selector lists are split one per line, and combinators like > get a space on each side. Blocks nested inside @media, @supports, @layer or native CSS nesting (the & syntax) get one extra level of indentation. Comments are kept where they were. Minify follows the CSS Syntax Module Level 3 from the W3C, which defines where whitespace is significant. It drops comments, line breaks, indentation and the final semicolon in each block. It keeps comments that start with /*!, since that is the common way to mark license headers. It also keeps spaces that carry meaning. The space in .card :is(.a) is a descendant combinator, and the spaces around + and - inside calc() or clamp() are required by the CSS Values spec. A quick example. Feed it h1,h2,.title>span{margin:0} in Beautify mode with 2 spaces. You get h1, then h2, then .title > span on separate lines, followed by an indented margin: 0; and a closing brace. Under the output, a counter shows input and output length in characters plus the ratio between them. What it won't do: it doesn't sort properties, merge duplicate rules, shorten colors or rewrite .8 into 0.8. It isn't a validator either, so broken CSS comes out broken, just formatted. The formatting happens in the page's own JavaScript. Your stylesheet is never uploaded, which makes it fine for pasting private or unreleased code.

Frontend developers who need to read a minified production stylesheet or tidy a pasted CSS snippet before committing it. The tool runs entirely in your browser, so your data never leaves your device.

02How to use CSS Formatter

  1. Paste your stylesheet into the Input CSS box
  2. Choose Beautify or Minify with the toggle at the top
  3. For Beautify, set Indent to 2 spaces or 4 spaces
  4. Click Format and check the result in the Output box
  5. Read the character counter under the output, then click Copy, or Reset to clear both boxes

03Worked examples

Input: .btn{color:#fff;background:red}.btn:hover{opacity:.8} (Beautify, indent 2)
Result: .btn { color: #fff; background: red; } .btn:hover { opacity: .8; }
Only whitespace changes. The value .8 is not rewritten to 0.8.
Input: h1,h2,.title>span{margin:0} (Beautify, indent 2)
Result: h1, h2, .title > span { margin: 0; }
Each selector in the list gets its own line and the > combinator gets spaces.
Input: .card{&:hover{color:red}} (Beautify, indent 2)
Result: .card { &:hover { color: red; } }
Native CSS nesting is indented one level per block.
Input: a{color:red!important;background:url(data:image/png;base64,AB;CD)} (Beautify, indent 2)
Result: a { color: red !important; background: url(data:image/png;base64,AB;CD); }
The semicolon inside the unquoted url() does not split the line.
Input: /* main */ .card { margin : 0 auto ; padding: 16px 24px; } (Minify)
Result: .card{margin:0 auto;padding:16px 24px}
The comment and the last semicolon go. The space in 0 auto stays because it separates two values.
Input: .x { width: calc(100% - 2rem); } (Minify)
Result: .x{width:calc(100% - 2rem)}
Spaces around - inside calc() are required by CSS, so they are kept.

04Common use cases

  • Reading a minified vendor bundle from DevTools to find which rule sets an unexpected margin
  • Re-indenting CSS copied out of a CMS or email template so a code review diff is readable
  • Splitting a long comma-separated selector list into one selector per line before editing it
  • Formatting CSS snippets for a blog post or internal docs at a consistent 2 or 4 space indent
  • Squashing a small critical-CSS block before pasting it into a style tag in the HTML head
  • Checking that a data URI or content string survives formatting without being cut at its semicolons

05Tips

  • Comments written as /*! ... */ survive Minify. Use that form for license headers you are required to keep.
  • A space before a colon in a selector changes its meaning. .card :hover targets a hovered descendant, while .card:hover targets the card itself, so the tool keeps that space.
  • Beautify leaves the @media prelude as you wrote it. (max-width:600px) is not respaced, so tidy it by hand if your style guide cares.
  • Minification only trims characters. Gzip or Brotli on your server cuts far more transfer size, so use both rather than picking one.

06Related concepts

CSS Modules, PostCSS, Sass, CSS custom properties.

Frequently Asked Questions

What is CSS Formatter?

CSS Formatter is a free, browser-based developer tool on AIDToolStack. Format, beautify, and minify CSS with indent options. It requires no installation or sign-up and works entirely in your browser.

Is CSS Formatter free to use?

Yes. No sign-up, no fees and no usage cap.

Does CSS Formatter store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Related Tools

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe