Web & CSS

CSS Formatter & Minifier

Paste CSS to format it with consistent indentation, or minify it to reduce file size. Everything happens in your browser.

Ready.

What it does

Beautify puts each rule and declaration on its own line with consistent indentation and puts selector lists one per line. Minify removes comments and unnecessary whitespace and drops the last semicolon in each rule, which shrinks the file without changing how it renders.

Safe by design

  • Text inside strings and url(...) (including data: URLs) is never reformatted.
  • Nested rules, @media, @supports and @font-face blocks are handled.
  • When minifying, comments beginning with /*! (licence notices) are kept.

Good to know

This is a formatter, not an optimiser: it does not merge rules, rename anything or remove unused CSS. For production builds, keep your original files and minify as part of your build process.

Example

Beautify turns @media (min-width:600px){.a,.b>c{margin:0 auto!important}} into an indented block with .a, and .b>c { on separate lines and margin: 0 auto !important; inside. Minify of the same input gives @media (min-width:600px){.a,.b>c{margin:0 auto !important}}, keeping the one space that !important needs. Running Beautify on its own output changes nothing.

Limits and warnings

  • The tool formats text; it does not know CSS properties, so a misspelt property or a bad value is formatted like a correct one.
  • If the input has an unclosed string or comment, or braces or parentheses that do not balance, the status line says so after the byte counts. The output is still produced but should not be trusted until the input is fixed.
  • Minifying a file that is already compact can make it slightly larger, and the status then reports a percentage "larger" instead of "smaller".
  • Colour values are left as written. To convert one to another notation use the Color Converter, and to check that a text and background pair is readable use the Color Contrast Checker. Sizes can be converted with the PX to REM Converter.

For a page that has CSS in a <style> block, format the markup with the HTML Formatter, Minifier & Validator and paste the CSS here.

Example

This minified CSS:

@media (min-width:768px){.card,.panel{display:grid;grid-template-columns:repeat(2,1fr);gap:1rem}}a:hover{color:#0a58ca;background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'/>")}/*! (c) licence */

is beautified with a 2-space indent into:

@media (min-width:768px) {
  .card,
  .panel {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
}

a:hover {
  color: #0a58ca;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'/>");
}

/*! (c) licence */

Rules inside a media query are indented one level deeper, and a list of selectors gets a line for each. The data URL and the comment that starts with /*! are kept exactly as they were, and Minify returns them untouched as well, because those comments usually carry a licence.

Frequently asked questions

Does minifying change how my CSS works?

No. It removes whitespace and unnecessary characters. Strings and data URLs are never altered.

Does it understand modern CSS such as nesting?

Nested rules and at-rules such as @media and @supports are formatted with the right indentation.

How do I convert units?

Use the PX to REM Converter.

Is my CSS uploaded?

No. It is formatted in your browser.

Privacy

This tool runs entirely in your browser. What you enter is processed on your device and is not sent to a server.

Share this tool

Your data is not included in this link.