A CSS beautifier turns minified, cramped or messy stylesheets into clean, readable code. Paste your CSS, choose an indent of two spaces, four spaces or a tab, and this CSS beautifier puts each selector, declaration and closing brace on its own line, indents the rules inside media queries, and adds a blank line between rules if you want one. Comments are kept, and nothing about how the CSS works is changed.
How to use the CSS beautifier
- Paste your CSS, whether it's one long minified line or a file with uneven spacing.
- Choose the indent: 2 spaces, 4 spaces or a tab.
- Choose how selectors are shown: one per line, or kept on one line.
- Choose whether to add a blank line between rules.
- Press Beautify CSS, then copy the result.
What CSS is made of
Cascading Style Sheets, CSS, is the language that styles web pages. A style sheet is a list of rules. Each rule has one or more selectors, which pick out the parts of the page it applies to, and a declaration block: a pair of braces around a list of declarations separated by semicolons. Each declaration is a property, a colon and a value, such as color: #333. White space around the braces, colons and semicolons is optional, which is why minified CSS can squeeze a whole stylesheet onto one line and still work.
Before and after
This minified CSS is hard to read:
.nav,.nav a{color:#333;padding:0 8px}@media (max-width:600px){.nav{display:none}}
With a two-space indent, one selector per line and blank lines between rules, the beautifier gives:
.nav,.nav a { color: #333; padding: 0 8px}@media (max-width:600px) { .nav { display: none }}
The result has the same rules, selectors and values, so the page looks exactly the same. Only the spacing has changed.
What the beautifier changes
- Line breaks: each declaration and each closing brace goes on its own line.
- Indentation: declarations are indented inside their rule, and rules inside media queries and other at-rules are indented one more level.
- Spacing: a space after each colon and before each opening brace, and a space after commas in values.
- Selectors: a selector list such as h1,h2,h3 can go one per line, which makes long lists easy to scan.
- Blank lines: optional blank lines separate rules.
It doesn't reorder properties, merge rules, remove duplicates, fix typos or add a semicolon after the last declaration of a rule, which CSS allows you to leave out.
When to beautify CSS
- Reading someone else's stylesheet, such as a theme or a library you need to customize.
- Debugging: it's much easier to find a rule when each one has its own lines.
- Learning: copy the CSS of a page you like and study how it's built.
- Tidying your own code before committing it, so that the whole team uses the same style.
- Reviewing changes: line-by-line differences are far clearer in formatted code.
Beautify or minify?
Beautifying and minifying are opposites. Beautified CSS is for people: it's easy to read and edit. Minified CSS is for browsers: removing white space and comments makes the file smaller, so it downloads faster. A common workflow is to keep readable source files, then minify them for the live site. To go the other way, use the CSS and JavaScript minifier.
Choosing an indent
Two spaces is the most common indent in CSS and keeps deeply nested media queries compact. Four spaces is easier to see at a glance. Tabs let each person set the width they prefer in their editor. Any of them is fine; what matters is using the same one everywhere in a project. If a project already has a style guide or a formatter configuration, follow it.
Comments and at-rules
Comments written between /* and */ are kept where they are, so notes and license headers survive. At-rules such as @media, @supports and @font-face are formatted too, with the rules inside them indented. If the number of opening and closing braces doesn't match, the tool still formats the CSS but warns you, because a missing brace usually means part of the stylesheet is broken.
Is my CSS private?
Yes. The CSS beautifier runs entirely in your browser, using the open-source js-beautify library. Your code is never uploaded, so it's safe to format stylesheets from private projects.
Formatting large stylesheets
The tool handles files of up to two million characters, which covers the stylesheets of almost any website or framework. For a very large file, it can help to beautify it once, save the readable copy, and then search it in your code editor. The line, rule and declaration counts shown with the result give a quick sense of how big and complex the stylesheet is.
Common mistakes
- Expecting it to fix errors. A beautifier changes spacing, not meaning; a missing brace or typo stays.
- Formatting the minified file you deploy. Keep the readable copy as your source and minify again for the live site.
- Mixing indent styles within one project.
What next
Use this often? Add CSS Beautifi to your Home screen.
Frequently asked questions
What does the CSS beautifier do?
It adds line breaks, indentation and spacing to CSS, so minified or messy stylesheets become readable, without changing how they work.
Does a CSS beautifier change how my page looks?
No. Only spaces and line breaks change; the selectors, properties and values stay the same.
Can I use tabs instead of spaces?
Yes. Choose 2 spaces, 4 spaces or a tab.
Are CSS comments kept?
Yes. Comments stay where they are in the formatted CSS.
Is my CSS uploaded?
No. It's formatted in your browser.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.