CSS Formatter & Minifier

Paste CSS to beautify it into clean, readable code or minify it for production. Supports all standard CSS including media queries, keyframes and custom properties. Runs entirely in your browser — your code is never uploaded.

When to beautify vs. when to minify

Situation Use Why
Reading or editing someone else's minified CSS Beautify Makes the structure legible so you can find and change rules
Debugging a style issue Beautify Each property on its own line makes it easy to spot typos and conflicts
Before committing to version control Beautify Consistent formatting means diffs show only meaningful changes
Shipping CSS to a production server Minify Reduces file size, improving page load time and Core Web Vitals
Embedding CSS in a build pipeline output Minify Bundlers and CDNs serve the compact version; humans edit the source

What this formatter does (and does not do)

  • Does: indent each property with your chosen spacing, put each selector and closing brace on its own line, add a blank line between top-level rules, and preserve /* comments */ in Beautify mode.
  • Does: strip all comments, collapse whitespace, and remove the trailing semicolon before } in Minify mode.
  • Does not: validate that your CSS is syntactically correct — it reformats what you give it.
  • Does not: add vendor prefixes (-webkit-, -moz-) or transform property names in any way.
  • Does not: compile SCSS, Less, or Sass — paste the standard CSS output from your preprocessor.
  • Does not: upload anything — all processing happens in your browser.

How the formatter works

The formatter reads your CSS one character at a time and tracks a small set of states: inside a comment (/* … */), inside a quoted string ("…" or '…'), or at the top level. Special characters — {, }, ; — are used to break the input into selectors, declarations, and blocks. The formatter never needs to understand what a selector or property means; it only cares about the structural characters. This makes it fast, dependency-free, and reliable across all standard CSS syntax including @media, @keyframes, @supports, custom properties (--variable), and calc() expressions.

Is my CSS private?

Yes. The formatting logic runs entirely in your browser using standard JavaScript. Nothing is sent to a server, so it is safe to paste internal stylesheets, design-system tokens, or unpublished code. The tool also works offline once the page has loaded.

Minification, gzip and Brotli: three layers that stack

It is easy to assume minification and server compression do the same job, but they work at different stages and combine rather than compete. Minification is a source-level transformation: it removes characters the CSS parser ignores — whitespace, comments and the final semicolon before a } — producing a file that is permanently smaller on disk and faster for the browser to parse. gzip and Brotli are transport-level compression: the server compresses the file just before sending it and the browser decompresses it on arrival, so the bytes that cross the network are far fewer than the file on disk.

gzip is built on DEFLATE (the LZ77 + Huffman algorithm also used inside ZIP and PNG); Brotli, released by Google in 2015, is a newer algorithm that ships with a built-in dictionary of common web text and typically beats gzip by around 15–20% on CSS and HTML. The two layers stack: you minify at build time, the server compresses at request time, and the user downloads the result of both. Minifying first actually helps the compressor too, because there is less redundant whitespace to model. The practical takeaway is that "gzip already compresses it" is not a reason to skip minification — they address different costs (parse time and on-disk size versus bytes on the wire), and the best result uses both.

Where minified CSS comes from in a real build

On a production site you rarely minify by hand — it happens automatically inside the build pipeline. A typical flow is: you (or a preprocessor like Sass) author readable, commented CSS; a bundler collects and processes it; and a minifier emits a compact .min.css that the CDN serves. The common tools each fill a slot:

  • cssnano — the most widely used CSS minifier, run as a PostCSS plugin; it does far more than strip whitespace (see the next section).
  • esbuild and Lightning CSS (used by Vite, Parcel and others) — extremely fast bundler-integrated minifiers written in Go and Rust.
  • Sass / Less — preprocessors that compile their own syntax down to plain CSS, which is then minified by one of the above.
  • Autoprefixer — a separate PostCSS step that adds vendor prefixes based on your browser-support targets; minifiers deliberately do not do this.

This tool sits in a different niche from a build pipeline. It is a quick, dependency-free, in-browser utility for the moments when you have a snippet to clean up or compress and do not want to spin up a whole toolchain — pasting a chunk of CSS from a tutorial, tidying a stylesheet a colleague sent, or shrinking a small file before dropping it into a CMS. It restructures exactly what you give it, instantly and privately.

The limits of a structural formatter

It is worth being precise about what this tool is and is not. It is a structural formatter: it reads your CSS character by character, tracking only the syntax — comments, quoted strings and brace depth — and reflows it. It never tries to understand what a selector or property means. That design is its strength (it is fast, reliable across every standard construct, and cannot accidentally change behaviour) and its boundary:

  • It will not merge duplicate rules, drop properties that are overridden later, or combine shorthand — those are semantic optimisations that need a full CSS model.
  • It will not shorten values (#ffffff#fff, 0px0) the way an advanced minifier like cssnano does.
  • It will not reorder or deduplicate selectors, because changing source order can change the cascade and therefore the rendered result.
  • It does not validate your CSS — if you feed it a missing brace, it reflows the broken input rather than reporting the error.

Those deeper transformations belong to a build-time optimiser working on an abstract syntax tree, where it can prove a change is safe. For everyday beautifying and basic minifying — the 90% case — a structural tool is exactly the right level: predictable output, no surprises, and nothing leaves your browser.

Source maps: debugging code you minified

Minified CSS is unreadable by design, which raises an obvious question: how do you debug a style bug in production when every rule is on one line? The answer is source maps — a companion .map file that records exactly which character in the minified output came from which line of your original source. When a browser's dev tools find a source map (referenced by a /*# sourceMappingURL=… */ comment at the end of the file), they let you inspect and step through the original, readable CSS even though the browser actually loaded the compressed version. Build tools generate these maps automatically alongside the minified file. If you ever need to reverse the process by hand — to read a minified file that has no source map — that is exactly what this tool's Beautify mode is for: paste the one-liner and get back indented, line-per-property code you can actually navigate.

A note on comments and licences

Minify mode strips all /* … */ comments because they cost bytes and have no effect on rendering. There is one widely-followed convention worth knowing about, though: many minifiers preserve "important" comments that begin with an exclamation mark — /*! … */ — which are conventionally used to keep a licence or copyright notice in the output. If you are minifying third-party CSS that carries a licence banner, check whether that licence requires the notice to survive; this tool removes all comments in Minify mode, so in that case beautify the file (which keeps comments), remove only what you safely can, and re-add the required banner by hand.

Frequently asked questions

How much does CSS minification actually save?
It depends on how much whitespace and how many comments are in the original file. Typical hand-written stylesheets minify to 30–60% of their original size. A file with extensive comments and generous spacing can shrink by 70% or more. In practice, minification is most impactful on files larger than a few kilobytes — below that, gzip compression already does most of the work.
Does minifying CSS change how it behaves in the browser?
No. Minification only removes characters that are invisible to the CSS parser — whitespace between tokens, comments, and the final semicolon before a closing brace. The selector names, property names, values, and cascade order are all preserved exactly. A correctly minified stylesheet produces byte-for-byte identical rendering to the original.
Can this tool add vendor prefixes like -webkit- or -moz-?
No. Vendor prefixes require knowing which CSS features need them for which browsers, which changes over time. Adding them correctly is the job of a tool like Autoprefixer (a PostCSS plugin). This formatter only restructures what you give it — it does not add, remove, or rewrite property names or values.
Does it support SCSS or Less?
No — this tool parses standard CSS only. SCSS and Less use additional syntax (nesting, variables with $ or @, mixins) that is not valid CSS. To format SCSS or Less, you need a dedicated formatter for those languages. You can, however, paste the compiled CSS output of your SCSS/Less build and format that.
Why does the beautifier keep my comments?
Comments are meaningful in development: they explain intent, mark sections, and disable rules during debugging. Beautify mode preserves them so you can still read and understand the code. Minify mode strips comments because they add bytes with no effect on rendering — use Minify only for production output you will not edit again.
How does the formatter handle media queries and keyframes?
The formatter tracks brace nesting depth, so rules inside @media, @keyframes, @supports, and other at-rules are indented one extra level. Each inner rule block gets its own indented property lines and its own closing brace on a separate line, matching the output you would expect from a code editor.

Related developer tools

See all tools →

Jelajahi alat lainnya

Lihat semua 70 alat →

Sematkan alat ini di situs Anda — gratis

Semua alat yang bisa disematkan →

Tambahkan CSS Formatter ke halaman, postingan, atau template apa pun. Gratis selamanya — tanpa pendaftaran, tanpa iklan di dalam widget. Satu-satunya syarat: pertahankan tautan atribusi kecil yang terlihat.

Pratinjau widget