Home › Developer Tools › CSS Formatter

CSS Formatter

Paste CSS to beautify it with clean, consistent indentation, sort the properties in each rule alphabetically, or minify it for production. Media queries, nesting and comments are handled.

Last updated:

Input CSS
Waiting for CSS…
Formatted CSS

      

Everything runs in your browser. Files you open are read locally and never uploaded.

Advertisement
Advertisement

How to use the CSS Formatter

  1. Paste your CSS into the input box or open a .css file. Try Sample to see an example.
  2. Choose the indentation (2 spaces, 4 spaces or tab) and options such as sorting properties or putting each selector on its own line.
  3. Press Format CSS. The formatted code appears on the right and updates as you type.
  4. Press Minify instead to strip comments and whitespace; the size saving is shown below the output.
  5. Copy or download the result as a .css file.

Before and after

Minified input:

.nav a:hover,.nav a:focus{color:#2f6b4f;text-decoration:underline}@media (max-width:600px){.nav{display:none}}

Formatted with 2 spaces, selectors on new lines:

.nav a:hover,
.nav a:focus {
  color: #2f6b4f;
  text-decoration: underline;
}

@media (max-width:600px) {
  .nav {
    display: none;
  }
}

What the formatter changes, and what it never touches

ChangedNever changed
Line breaks and indentationText inside strings, such as content: "a , b"
One space after : and after commas in valuesUnquoted url(…) values, including data URIs
Spaces around >, + and ~ combinatorsCustom property values (--name: …), kept exactly as written
Spacing before !importantComments (in Format mode) and the order of rules

Minify mode removes comments except /*! … */ licence comments, which are kept by convention. It also removes spaces around braces, colons, semicolons and commas, and the last semicolon in each rule. Spaces inside calc() are kept, because calc(100% - 2rem) stops working without them.

How property sorting works

With Sort properties on, declarations inside each rule are put in alphabetical order. Custom properties stay at the top in their original order. Vendor-prefixed versions such as -webkit-transition are placed directly before the standard transition instead of being grouped at the top. Repeated properties used as fallbacks, for example display: -webkit-box followed by display: flex, keep their order so the fallback still works. A comment directly above a declaration moves with it.

Alphabetical order makes it easy to see whether a property is already set and reduces merge conflicts. Watch out for a shorthand written after one of its longhands (border-top then border): sorting swaps them, and the later declaration is the one that applies.

Frequently asked questions

What does a CSS formatter do?

It rewrites CSS with one declaration per line and consistent indentation inside each rule and media query, so the stylesheet is easy to read and edit. It does not change what the CSS does.

Can I unminify CSS?

Yes. Paste minified CSS, for example from a production website, and press Format CSS. Every rule and declaration is put back on its own line. Comments that were removed during minification cannot be recovered.

Is sorting CSS properties safe?

Usually. Sorting only reorders declarations inside the same rule. It can change the result when a shorthand comes after a longhand of the same property, for example border-top followed by border, because the later declaration wins. Sorting keeps duplicate properties such as fallback values in their original order.

How much does minifying CSS save?

Typically 15 to 30 percent for hand-written CSS, more if it has many comments. The tool shows the exact size before and after. Servers that use gzip or Brotli compression shrink the difference further, but minification still helps.

Does it support SCSS or Less?

Plain CSS, CSS nesting and most SCSS that uses nested rules and variables format well because the structure is the same. Special syntax like mixins with arguments may not format perfectly.

Is my CSS uploaded?

No. Formatting happens entirely in your browser, so your code never leaves your device.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

HTML FormatterBeautify and indent HTML code with a live preview.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.XML FormatterBeautify, validate and minify XML with a collapsible tree view.Meta Tag GeneratorCreate SEO, Open Graph and X meta tags with live previews.CSS Border Radius GeneratorRound each corner, draw elliptical 8-value radii or random blob shapes and copy the CSS.CSS Box Shadow GeneratorDesign layered CSS box shadows with a live preview, presets and one-click Copy CSS.CSS Button GeneratorDesign CSS buttons with gradients, borders, shadows and hover and active states, then copy the code.CSS Flexbox GeneratorBuild flexbox layouts visually: set container and item properties, then copy the CSS and HTML.ZIP File CreatorCompress files and folders into a ZIP.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.Code Diff CheckerCompare two code files side by side or unified, with syntax colors and changes highlighted.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.GraphQL FormatterPretty-print and indent GraphQL queries, mutations and schemas, or minify them, instantly.CSS ValidatorValidate CSS: syntax errors, unknown properties and invalid values by line, plus auto-fix.Gzip Compress / DecompressGzip or deflate text and files, get Base64 output, and decompress Base64 or .gz files.IBAN ValidatorCheck an IBAN's mod-97 checksum, country and length, and see its bank code and account parts.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JSON Schema ValidatorValidate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with clickable error paths.Markdown FormatterBeautify Markdown with Prettier: list markers, prose wrap, aligned tables and live preview.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.TypeScript FormatterFormat TypeScript and TSX code with Prettier: width, tabs, semicolons and quotes options.XML MinifierMinify and validate XML: strip whitespace and comments, keep CDATA, see the size savings.C# FormatterBeautify C# code online: Allman or K&R braces, indent size and line width, clang-format option.HTML ValidatorCheck HTML for errors and warnings with line numbers, locally or with the W3C Nu checker.Java FormatterBeautify Java code online: indent size, brace style and line width, with clang-format option.JavaScript ObfuscatorObfuscate JavaScript with string encoding, renaming and control-flow flattening presets.Phone Number FormatterFormat and validate lists of phone numbers to E.164, international or national style.Python FormatterFormat Python code in Black/Ruff style: line length, quote style, indent, copy or download.Responsive Design CheckerPreview any website at phone, tablet, laptop and desktop sizes side by side, with rotate and zoom.Browser Compatibility CheckerSearch CSS, JavaScript and HTML features and see which browser versions support them.Core Web Vitals CheckerCheck real-user LCP, INP and CLS for any URL or site and see if it passes Core Web Vitals.Heading Structure CheckerPaste HTML to see its H1-H6 outline and catch missing H1s, multiple H1s and skipped levels.Website Hosting CheckerFind out who hosts a website: hosting provider, IP addresses, ASN, network owner and location.Routing Number ValidatorCheck a US ABA routing number's checksum and format and see its Federal Reserve district.Spam Word CheckerScan an email subject and body for spam trigger words, excess caps, exclamation marks and risky links.Check Digit CalculatorCalculate or validate check digits for UPC, EAN, GTIN, SSCC, ISBN, ISSN and mod 11 codes.Luhn Algorithm CheckerValidate numbers with the Luhn mod 10 check or calculate the missing check digit, step by step.Strftime Format BuilderBuild Python and C strftime format strings by clicking tokens, with a live preview and reference.XSD ValidatorValidate XML against an XSD schema in your browser and see each error with its line number.
See all 41 Code Formatters & Validators →