CSS formatter and minifier

Beautify messy CSS or minify it for production, with the size saved. Free, no sign-up, and everything runs in your browser.

Action

Indent

Paste a stylesheet. The result updates as you type.

Formatted CSS

427 B to 514 B
/*! Launch page styles */
.hero,
.hero--dark {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  padding: 64px 16px;
}

.hero h1 {
  font: 700 clamp(2rem, 5vw, 3.5rem)/1.1 "Inter", system-ui, sans-serif;
  margin: 0 0 16px;
}

/* Call to action */
.cta > a:not(.secondary):hover {
  background: url(/img/arrow.svg) no-repeat right center;
  color: #fff !important;
}

@media (max-width: 600px) {
  .hero {
    padding: 32px 16px;
  }

  .cta {
    display: none;
  }
}

What this CSS formatter does

This tool takes a stylesheet in any shape and gives it back in the shape you need. Beautify puts each selector and each declaration on its own line, indents nested blocks, and adds one space after every colon and comma. Minify does the opposite: it removes comments, line breaks and every space the browser does not need, so the file is smaller.

It only changes whitespace, comments and the last semicolon in a block. It never rewrites selectors or values, so the output means exactly the same as the input. Strings, url() values, !important, media queries and native CSS nesting stay as they are. Everything runs in your browser tab, and nothing is uploaded.

How to format or minify CSS

  1. Paste your CSS into Your CSS. Minified CSS from a live site works too: open the stylesheet in your browser's developer tools and copy it.
  2. Pick Beautify to make it readable, or Minify to make it small. The result updates as you type.
  3. When you beautify, pick an indent of 2 spaces, 4 spaces or a tab. When you minify, choose whether to keep comments that start with /*!. Tools and authors use that form for license notes that must stay in the file.
  4. Select Copy CSS, or Download to save the result as a .css file. The badge shows the size before and after.

If the tool finds a problem, such as a block that is never closed or a line without a colon, it lists the line number. It still makes the output, but fix the line first: browsers do not show CSS errors. They skip the broken part without a warning and keep going, so one missing brace can quietly drop the rules after it.1

Why minify CSS

A browser must download and read your CSS before it can draw the page, so smaller files help pages show up sooner. Google's Lighthouse audit flags unminified stylesheets and estimates the savings from the comments and whitespace it finds.2 Google's guide suggests a build step that minifies CSS automatically for sites you deploy often, and a paste-in tool for small sites you rarely change.2 This tool covers the second case and any time you have no build step, such as a static landing page, a theme file in a site builder, or a quick snippet for an email or a widget.

Minify for production and keep the readable version as your source. You can always beautify a minified file again to read or edit it. If you are tuning a site before a product launch, also check that crawlers can reach your stylesheets with the robots.txt tester, and compare two versions of a file with the diff checker.

Frequently asked questions

Sources

  1. MDN Web Docs: CSS error handling

  2. Chrome for Developers: Minify CSS (Lighthouse audit)

  3. MDN Web Docs: Comments

  4. W3C: CSS Syntax Module Level 3 (consume comments)

  5. MDN Web Docs: Using CSS nesting