How to use the CSS formatter
- Paste, drop or open a stylesheet in the left pane.
- Choose Language: CSS, SCSS or Less. Nesting, variables and mixins are understood in the SCSS and Less modes.
- For formatted output, pick Indent (2 spaces, 4 spaces or Tabs) and Quotes (“Double” or ‘Single’).
- With CSS selected, turn on Minify to get the smallest safe version instead.
Formatting uses Prettier, so the result matches what Prettier produces in your editor with the same settings.
Example
.card>a:hover,.card>a:focus{color:red;content:"★"}
becomes
.card > a:hover,
.card > a:focus {
color: red;
content: "★";
}
Each selector in a list gets its own line, combinators get spaces, and every declaration ends with a semicolon. With Quotes set to ‘Single’, the string becomes '★'.
Safe minification
A regex-based minifier can break CSS, because some whitespace is meaningful. This tool first normalizes the stylesheet with Prettier, then removes only whitespace that doesn’t matter, and drops comments except /*! … */ license comments.
/* note */ .a { width: calc(100% + 2px); }
nav :hover { color : red !important; }
.b::before { content: "a ; b c" }
minifies to
.a{width:calc(100% + 2px)}nav :hover{color:red!important}.b::before{content:"a ; b c"}
| Kept | Why |
|---|---|
calc(100% + 2px) |
+ and - in calc() require spaces |
nav :hover |
The space means “any descendant” |
"a ; b c" |
String contents are never touched |
/*! … */ |
License comments are preserved by convention |
The status bar shows the size before and after, for example Minified · 116 → 87 characters.
SCSS and Less
$c: red; .a { .b { color: $c; } }
is formatted as nested blocks with one declaration per line. Minify is hidden for these languages: compile them first, then minify the output CSS.
Doing it locally
npx prettier --write "src/**/*.{css,scss,less}"
npx prettier --single-quote styles.css
Custom properties such as --brand: #5b5bf0 and modern syntax like rgb(91 91 240 / 0.25) are formatted like any other declaration. For production builds, let your bundler minify CSS (Vite, esbuild and Lightning CSS all do); this minifier is for quick one-off cases such as inlining a snippet into an email or a page.
When to use it
- Reading production CSS. Stylesheets copied from a CDN or the browser’s DevTools are often one long line. Formatting restores one rule per block so you can find the selector you need.
- Reviewing changes. Format both versions with the same settings, then compare them in Text Diff, so only real changes remain.
- Inline snippets. Minify a small block before inlining it in an HTML email or a
<style>tag.
Invalid CSS stops with the exact location, for example CssSyntaxError: Unclosed block, and Jump to error moves the cursor there. For long stylesheets, the Full screen button gives both panes the whole window.
Related tools
Format the page around your styles with the HTML Formatter, scripts with the JavaScript Formatter, and compare two versions of a stylesheet with Text Diff.
Frequently asked questions
Is my CSS uploaded?
No. Formatting and minifying run in your browser with Prettier and nothing is uploaded.
Can I minify SCSS or Less?
No. Minify is available for plain CSS only, because SCSS and Less must be compiled before they can be minified. Compile them with Sass or Less first, then minify the resulting CSS here.
Is the minifier safe for strings and calc()?
Yes. The CSS is parsed and normalized by Prettier first, and whitespace is only removed where it has no meaning. Strings like content: "a ; b", the spaces required around + and - in calc(), and the descendant space in selectors such as nav :hover are kept.
Why don't I see the Indent, Line width and Quotes options?
They only affect formatted output, so they are hidden while Minify is on. Turn Minify off to set them again.
What happens with invalid CSS?
Syntax errors stop formatting and point to the line and column, for example CssSyntaxError: Unclosed block on line 1, column 2, with a button to jump to the error in the editor.
Last updated