CSS Minifier & Beautifier

Compress CSS for production or format it for reading — safely, and without leaving your browser.

Your CSS is processed locally in your browser and never uploaded.

Advertisement

How to Use This CSS Minifier

Paste a stylesheet into the input box, open a .css file from your computer, or click Sample CSS to see the tool work on a small example. In Minify mode the output updates shortly after you stop typing, and the size panel shows the original and minified byte counts, the percentage saved, and a bar that visualises the reduction. Use Copy to put the result on your clipboard or Download to save it as styles.min.css. Switch to Beautify to do the opposite: expand compressed or messy CSS into consistently indented code with one declaration per line, using two spaces, four spaces, or tabs.

By default the minifier keeps comments that begin with /*!, the common convention for license and copyright notices, and removes every other comment. Untick the option if you want those gone as well. If the status line reports unbalanced braces, your input has a missing { or }; the tool still produces output, but you should fix the source first because browsers recover from such errors in ways that are easy to misread.

What the Minifier Changes

Minification removes bytes that the browser does not need while keeping the stylesheet's meaning identical. This tool applies a deliberately conservative set of changes:

  • Removes comments, except preserved /*! ... */ comments.
  • Collapses runs of whitespace and deletes it entirely where the grammar allows, such as around {, }, ;, ,, the colon in a declaration, and the >, +, and ~ combinators in selectors.
  • Drops the final semicolon before each closing brace, and empty statements like ;;.
  • Writes zero lengths without a unit (0px becomes 0) and removes leading zeros (0.5em becomes .5em).
  • Shortens hex colors when every pair of digits repeats, so #ffffff becomes #fff and #aabbccdd becomes #abcd.

It does not reorder rules, merge selectors, remove duplicate declarations, or rename anything. Those optimisations can save more bytes, but they rely on assumptions about the cascade that are easy to get wrong, and they belong in a full build pipeline where the output is tested.

How It Avoids Breaking Your CSS

Advertisement

A minifier built from a few regular expressions will eventually corrupt something, because the same characters mean different things in different places. A semicolon inside content: "a; b" is text, not the end of a declaration, and /* inside a string is not a comment. This tool reads the stylesheet as a sequence of tokens first: strings, comments, unquoted url(...) values, bracketed attribute selectors, punctuation, and words. Whitespace and comment removal happen only between tokens, so the contents of strings and URLs are copied exactly.

It also tracks context, because some spaces are meaningful. Inside calc(), the spaces around + and - are required by the specification, so calc(100% - 10px) keeps them. In selectors, a space is the descendant combinator: a :hover means any hovered element inside a link and is different from a:hover, so that space stays. In an at-rule like @media screen and (max-width: 600px), the space between and and the parenthesis must remain, or the browser would read and( as a function name. Custom properties such as --gap: calc( 1rem + 4px ) are copied with only their surrounding whitespace trimmed, because their values are passed to var() as raw tokens.

Zero-unit shortening is skipped where a bare 0 would change meaning: inside math functions like calc(), min(), max(), and clamp(), in the flex shorthand, and for non-length units such as 0s and 0deg. Hex shortening only touches values in declarations, so an ID selector like #aabbcc is never rewritten.

Why Minify CSS at All?

CSS blocks rendering: browsers generally will not paint a page until the stylesheets in its <head> have downloaded and been parsed. Smaller stylesheets arrive sooner, which helps metrics such as First Contentful Paint, especially on slow mobile connections. Minification also reduces bandwidth for every visitor and every cache miss. The savings are largest on hand-written files with long comments and generous indentation, and smallest on stylesheets that were already generated compactly by a framework.

Minifying works alongside HTTP compression rather than replacing it. Servers and CDNs usually compress text files with gzip or Brotli, which are very good at squeezing repeated whitespace, so the transfer-size gain from minification is smaller than the raw byte difference shown here. Removing comments still helps, since compression cannot drop text that is genuinely unique, and minified files are faster to parse because there is simply less to read.

When to Beautify Instead

Beautify mode is the tool for reading code you did not write or no longer remember: a minified file from a third-party widget, CSS copied from browser developer tools, or a stylesheet whose indentation has drifted after years of edits. It places each selector in a list on its own line, puts every declaration on a separate indented line, nests @media, @supports, and nested rules visibly, and adds a missing final semicolon so the next property you add will not be swallowed by the previous one. Comments are preserved and values are not altered, so formatted output behaves exactly like the input.

A useful workflow is to beautify a minified file, make your change, and then minify again for deployment. Better still, keep the readable version under version control and let your build tooling produce the minified file, so the copy that people edit is always the formatted one.

Tips, Limits, and Alternatives

  • Always keep the original. Minified CSS is an output, not a source file. Store the readable version and regenerate the minified copy when it changes.
  • Test after minifying. This tool is careful, but unusual syntax such as old Internet Explorer hacks or invalid CSS can be interpreted differently by different tools. Load the page with the minified file and check it.
  • Use source maps in larger projects. Build tools such as Lightning CSS, cssnano with PostCSS, or esbuild can minify as part of your pipeline and emit source maps, so browser developer tools show original line numbers.
  • Remove unused CSS separately. Minification shortens the CSS you have; it does not know which rules your pages never use. Coverage reports in browser developer tools show unused rules, but review them carefully before deleting anything that might be needed by states or pages you did not test.
  • Inline assets thoughtfully. Embedding small images as Base64 data URIs saves a request but makes the stylesheet larger and harder to cache separately, so use it for tiny icons rather than photos.

Frequently Asked Questions

Is it safe to minify CSS?

Yes, when the minifier understands CSS syntax. This tool tokenizes the stylesheet instead of using blind find-and-replace, so it leaves strings, url() values, attribute selectors, and custom properties intact and keeps the spaces that carry meaning, such as those around + and - inside calc() and the descendant space in selectors like a :hover. Keep your original source file and test the minified output, as you would after any build step.

How much smaller will my CSS get?

It depends on how the file was written. Hand-written CSS with many comments and generous indentation shrinks noticeably, while CSS that is already compact gains little. The size panel shows the exact before and after byte counts for your input. Remember that servers usually compress CSS with gzip or Brotli as well, which reduces the transfer size further.

What does /*! mean in a CSS comment?

A comment that starts with /*! is a widely used convention for marking text that should survive minification, typically a license or copyright notice. This minifier keeps those comments by default and removes all ordinary comments. You can switch the option off if you do not need them.

Why are some 0px values not shortened to 0?

A unitless zero is not always equivalent. Inside calc(), min(), max(), and clamp() a bare 0 is a number rather than a length and can make the whole expression invalid, and in the flex shorthand a unitless 0 can be read as a flex factor instead of a basis. The minifier leaves those cases, time values like 0s, angles like 0deg, and custom properties untouched.

Does the beautifier change how my CSS works?

No. Beautify mode only changes whitespace and line breaks: it puts each declaration on its own line, indents nested blocks, and adds a final semicolon where one was omitted. Comments are kept. Values are not rewritten, so you can safely format minified CSS to read or debug it.

Related Articles

Expert guides and educational resources to help you master the math.

Advertisement