CF
CSS Formatter & Minifier
Expand CSS into one readable declaration per line, or minify it down to a single compact line.
More Developer Tools Tools
How to Use CSS Formatter & Minifier
Paste CSS into the box. Format expands every rule and declaration onto its own indented line for readability. Minify strips comments and all unnecessary whitespace, producing the smallest equivalent single-line stylesheet. Both use a small brace/semicolon-based tokenizer running entirely in your browser.
About CSS Formatter & Minifier
CSS (Cascading Style Sheets) styles every web page, and its syntax is comparatively simple compared to a full programming language: a stylesheet is a sequence of rules, each rule is a selector followed by a block of semicolon-separated declarations in curly braces, and declarations are property:value pairs. That regularity — braces open and close blocks, semicolons end declarations — is exactly what makes it practical to format or minify with a straightforward tokenizer rather than a full parser, and this tool does exactly that: it walks the CSS text character by character, tracking brace depth and recognising selectors, declarations, comments and at-rules (@media, @font-face, @keyframes, and so on).
Formatting exists because CSS is very often edited by hand and readability matters for maintenance: a stylesheet with everything crammed onto one line is nearly impossible to scan or diff in version control, while one declaration per line with consistent indentation makes it obvious at a glance which properties apply to which selector, and makes changes show up as small, readable diffs. Minifying exists for the opposite reason: in production, whitespace and comments add bytes to every page load with zero effect on rendering, so stripping them (and normalizing details like removing the space after a colon, or the trailing semicolon before a closing brace) reduces file size and, at scale, improves page load time — this is one of the most common web performance optimisations and is why virtually every production build pipeline includes a CSS minification step.
Because the tokenizer tracks nesting depth via braces, it correctly handles at-rules that themselves contain nested rule blocks, such as @media queries wrapping multiple selectors, or @keyframes with percentage-based steps (0% { ... } 50% { ... } 100% { ... }) — each nested block is indented one level deeper than its containing at-rule. It also understands CSS comments (/* ... */) and strips them during minification while preserving them (on their own line) during formatting, and it treats content inside quoted strings (e.g. content: "a; b" or a url() with special characters) as opaque text rather than syntax, so semicolons or braces that happen to appear inside a quoted string do not confuse the brace/semicolon counting.
What this tool does not do is validate that your CSS is semantically correct — it will happily format a stylesheet that uses a property name that does not exist, or a color value that is not valid, because that is a question of CSS semantics, not syntax structure, and checking it would require a full property/value grammar for every current and historical CSS property. It also treats modern CSS nesting syntax (native CSS nesting, where a selector can be written inside another selector's block without needing a preprocessor) the same way it treats any other nested block, since structurally it is just another set of braces — but it does not resolve or expand what the nested selector would compile to, it simply formats the nesting as written. For CSS-specific linting (catching invalid properties, duplicate declarations, or accessibility issues like insufficient color contrast), a dedicated tool such as Stylelint is the right choice; this tool's job is purely making CSS readable or compact, not validating what it says.
Details & Tips
How Format works: the tokenizer walks the CSS, and on encountering a selector followed by { it prints the selector, opens a block, and increases indentation by two spaces; each declaration inside gets its own line as property: value; and on encountering } it decreases indentation and closes the block on its own line. At-rules like @media and @keyframes that contain nested rule blocks are indented recursively, so a selector inside a @media query sits one level deeper than the @media line itself, and its declarations sit one level deeper still.
How Minify works: comments are stripped, then all whitespace that is not required for correctness is removed — spaces around {, }, :, ; and , are eliminated, the trailing semicolon before a closing } is dropped (it is optional in CSS and removing it saves a byte with no effect), and the entire stylesheet is emitted as a single unbroken line. Content inside quoted strings and inside url(...) is preserved exactly, since whitespace or special characters there can be semantically meaningful (for example a font file path or generated content text).
Worked example:
Input (minified, hard to read): `.btn{color:#fff;background:#333}.btn:hover{background:#555}`
Formatted output:
```
.btn {
color: #fff;
background: #333;
}
.btn:hover {
background: #555;
}
```
What is out of scope: this tool checks and preserves syntactic structure (braces, semicolons, selector/declaration boundaries) but does not validate CSS semantics — it will not warn you about an unknown property, an invalid value, a typo in a hex color, or a selector that matches nothing. It also does not resolve CSS custom properties (variables), preprocess Sass/Less syntax, or autoprefix vendor-specific properties. For linting CSS correctness, use a dedicated tool such as Stylelint; for Sass/Less, compile first and then format the resulting plain CSS with this tool if desired.
Frequently Asked Questions
Does this CSS formatter validate my CSS?
No, it only handles syntactic structure — braces, semicolons, selectors and declarations. It does not check whether property names or values are valid CSS; use a dedicated linter such as Stylelint for that.
How does Minify shrink the file?
It strips comments, removes all whitespace that is not required for the CSS to parse correctly (around colons, semicolons, braces and commas), drops the optional trailing semicolon before a closing brace, and joins everything onto one line.
Does formatting handle @media queries and @keyframes correctly?
Yes, nested at-rule blocks are indented recursively based on brace depth, so selectors inside a @media query and steps inside a @keyframes block are indented one level deeper than usual.
Will minifying break a url() with special characters or a content string?
No, the tokenizer treats content inside quotes and inside url(...) as opaque text and leaves it untouched, so semicolons, braces or spaces inside those are preserved exactly.
Does this support Sass or Less syntax?
No, this formats plain CSS only. Compile your Sass/Less to CSS first, then format the output here if you want it readable.
Does it support native CSS nesting?
Yes structurally — nested selectors inside a block are formatted with increasing indentation like any other nested braces — but the tool does not resolve or expand what the nesting compiles to.
Is my CSS uploaded anywhere?
No, formatting and minifying both happen locally in your browser using JavaScript.
Are CSS comments preserved?
Format keeps comments on their own line in the output. Minify strips all comments, since they have no effect on rendering and only add file size.
Can I format a full stylesheet with hundreds of rules?
Yes, there is no artificial size limit, though very large stylesheets (hundreds of KB) may take a brief moment to process since everything runs in the browser tab.
Does minifying rename or shorten selectors and class names?
No, this tool only removes whitespace and comments — it does not rename classes, merge duplicate rules, or apply any other CSS-specific optimisation beyond whitespace stripping.
Part of These Collections
Also Available As
css formatter, css minifier, css beautifier, pretty print css, format css online, css compressor, minify stylesheet
Found a Problem?
Let us know if something with CSS Formatter & Minifier isn't working as expected.
Something went wrong. Please try again.
Thanks — we'll take a look.