About this tool
Minified CSS is great for page speed and terrible for reading. This CSS formatter (or CSS beautifier) turns a one-line stylesheet into readable rules: one declaration per line, consistent indentation, and one selector per line. Click Minify to go the other way and strip the whitespace and comments for production. It runs entirely in your browser, so your stylesheets never leave your machine.
How to use it
- Paste CSS into the box, drop a
.cssfile onto it, or click Open file. - The formatted result appears as you type. Choose 2 spaces, 4 spaces or tabs for indentation.
- Click Minify for the smallest version, then Copy or Download the result.
Before and after
This minified CSS:
.card{display:flex;gap:12px;padding:16px 20px;border:1px solid #e5e7eb;border-radius:12px}.card:hover,.card:focus-within{box-shadow:0 4px 12px rgba(0,0,0,.08)}@media (max-width:600px){.card{flex-direction:column}}
becomes:
.card {
display: flex;
gap: 12px;
padding: 16px 20px;
border: 1px solid #e5e7eb;
border-radius: 12px;
}
.card:hover,
.card:focus-within {
box-shadow: 0 4px 12px rgba(0, 0, 0, .08);
}
@media (max-width: 600px) {
.card {
flex-direction: column;
}
}
What the formatter changes, and what it never touches
- Changes: line breaks, indentation and spaces. A space follows each
:in declarations and each comma in values, combinators like>and+get spaces around them, and a missing final semicolon is added. - Never touches: the text inside strings,
url(…)values (including data URIs that contain;or{), attribute selectors and comments. Property and selector names keep their case. - Doesn’t reorder or rewrite rules. It won’t merge shorthands, sort properties or remove duplicates, so the formatted stylesheet behaves exactly like the original.
It understands media and container queries, @supports, @font-face, @keyframes, @layer and native CSS nesting. If a brace or quote is missing, the formatter still produces output and tells you what it had to fix.
What minifying removes
Minify removes comments (except /*! … */ licence comments, which by convention must be kept), line breaks, indentation, spaces around { } : ; , and selector combinators, and the last semicolon in each block. Spaces that matter, such as in calc(100% - 2rem) or between the values of margin: 0 auto, are kept. Typical hand-written stylesheets shrink by roughly 15–35% before compression.
For production builds, let your build tool do it: it can also merge rules, shorten colours and drop unused vendor prefixes, which a safe online minifier shouldn’t attempt. Gzip or Brotli compression from your server or CDN saves far more on top.
Format and minify CSS in your project
# Format every stylesheet in place (also handles SCSS and Less)
npx prettier --write "src/**/*.css"
# Check formatting in CI without changing files
npx prettier --check "src/**/*.css"# Minify for production
npx esbuild styles.css --minify --outfile=styles.min.css
# Bundle @import-ed files and minify in one step
npx esbuild styles.css --bundle --minify --outfile=dist/app.css// settings.json: format CSS on save with the built-in formatter
{
"[css]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "vscode.css-language-features"
},
"css.format.spaceAroundSelectorSeparator": true
}CSS formatting conventions
- One declaration per line, ending with a semicolon, so diffs show exactly what changed.
- One selector per line in a selector list. Long lists stay readable and reviewable.
- A blank line between rules and lowercase hex colours are common choices; pick one style and let a formatter enforce it.
- Custom properties (
--brand: #0b5;) for values used in several places, so a theme change is a one-line edit.
FAQ
How do I beautify minified CSS?
Paste it into the box above. It is formatted instantly with one declaration per line and consistent indentation. Copy it or download it as a .css file.
Does formatting change how my CSS works?
No. Only whitespace changes, plus a final semicolon in blocks that lack one. Strings, url() values, comments and the order of rules stay exactly as they were.
Can it format SCSS or Less?
It is built for plain CSS, including native nesting. SCSS and Less add syntax such as // comments and #{} interpolation that it doesn’t understand, so use Prettier for those.
Is minified CSS faster?
Smaller files download faster, especially on mobile. Minifying typically saves 15–35% before compression; enabling gzip or Brotli on your server saves considerably more.
Are license comments kept when minifying?
Yes. Comments that start with /*! are preserved, as most licences require. All other comments are removed.
Is my CSS uploaded anywhere?
No. Formatting runs in your browser, in a background worker, so nothing is sent to a server.