Developer
CSS Beautifier
Turn cramped CSS into a readable stylesheet with two-space or four-space indentation, or compress it to a single line. Copy or download the cleaned result.
Paste CSS to beautify or minify.
CSS output
—
Output actions
Ready to copy output once your result appears.
Two or four spaces, or one compacted line
CSS Beautifier walks the paste as characters. Beautify is selected on arrival, and the indent menu offers 2 spaces or 4 spaces. A declaration that ends with a semicolon is rewritten with a space after the colon. A declaration that is closed only by a brace is written as the buffer held it, without that spacing pass and without a semicolon added. Minify removes block comments and squeezes the sheet onto one line. Copy output and Download output read the pane. The file name is css-beautifier.txt.
How to reindent a stylesheet
- 1Paste into CSS input, or press Load sample. The sample is two rules, .card and .card h2, each on one line with no spaces around the braces. The box starts empty.
- 2Stay on Beautify and leave Indent size at 2 spaces, or switch to 4 spaces. The menu is hidden while Minify is selected. The menu does not rerun.
- 3Press Beautify CSS, or switch to Minify and press Minify CSS. The button label follows the mode. Success says CSS beautified. or CSS minified. An empty box says Paste CSS to format. or Paste CSS to minify. and clears the pane.
What it is good for
- • Stacking the declarations of a minified rule, with a two-space or four-space pad.
- • Seeing that the last declaration in the sample has no semicolon and no space after the colon.
- • Stripping a block comment and the spaces around braces in one Minify click.
Example
Input
.card{padding:1rem;color:#111}.card h2{font-size:1.25rem;margin:0}Output
.card {
padding: 1rem;
color:#111
}
.card h2 {
font-size: 1.25rem;
margin:0
}Beautify at 2 spaces. padding and font-size end with semicolons, so they gain a space after the colon. color and margin do not, so they stay tight and lose no character that was never there. Four spaces uses four spaces at each level and the same declaration text.
What the brace walk changes
Beautify trims the paste, rejects an empty result, then deletes every /* */ block comment, non-greedy, before it walks. An unclosed comment is left in place because the pattern never finds the closer. The walk keeps a buffer and a depth. A { flushes the buffer with a space before the brace, then increases depth. A } flushes whatever is still buffered, decreases depth, and writes the closing brace at the new depth. A ; runs the declaration through a spacing pass first: space around the colon becomes a single space after the colon, other whitespace runs become one space, and the semicolon is kept.
The spacing pass does not run for text that reaches a } without a semicolon. That is why color:#111 in the sample is still color:#111 on its own line, with no semicolon added, while padding:1rem becomes padding: 1rem; because that declaration had a semicolon. If you add the missing semicolon, color: #111; is what Beautify writes. Newlines in the source become spaces in the buffer, so a declaration that was already wrapped is joined before it is split again on semicolons and braces. The indent string is two U+0020 characters, or four when that option is selected. Depth never goes below zero.
Beautify, Minify, and the indent menu
Beautify and Minify are a two-button group. Beautify starts pressed. Indent size appears only then, as a select whose options are 2 spaces and 4 spaces. 2 spaces is the initial value. Choosing 4 spaces does nothing until Beautify CSS is pressed. In Minify the select is not rendered, and the indent value is ignored because Minify does not read it.
Minify also strips block comments, then collapses whitespace, removes space around braces, semicolons, and colons, and turns ;} into }. The sample, after a Beautify, minifies back to the one-line sample. A rule whose last declaration had a semicolon loses that semicolon in Minify because of the ;} replacement, so .a { color: red; } with a leading comment becomes .a{color:red}. The status on success is CSS beautified. or CSS minified. Copy output copies the pane. Download output saves css-beautifier.txt. Load sample only fills the box.
When a reindented sheet is the right view
Use Beautify when a rule you copied from a built file is one long line and you want each declaration on its own line. Use Minify when you want that line back, with comments gone. This walk is not a stylesheet engine. It does not reorder properties, expand shorthand, or convert a color. A hex value you want as rgb() belongs on the color converter. A set of related hex colors belongs on the color palette generator.
HTML indent, including a tab choice this page does not have, is the HTML beautifier. Paste a style element there and you are indenting markup, not walking CSS braces. Markdown that should become tags first is Markdown to HTML. Bring the CSS here only after you have a stylesheet, not a Markdown fence.
Comments, missing semicolons, and quoted semicolons
Both modes delete block comments before any other rewrite. A comment between properties disappears, and the declarations on either side are still processed. A comment that never closes stays in the buffer and can glue itself to a nearby declaration. There is no line-comment syntax here. Two slashes are ordinary characters.
The walker does not understand strings. A semicolon inside quotes is still the semicolon that ends a declaration, so content:"a;b" is split into two lines and the quote is broken. A brace inside a string would change depth the same way. @media and other at-rules that use braces nest, because each { increases depth and each } decreases it. An @import that ends with a semicolon is flushed as its own line on Beautify. Empty input, or input that is only spaces, throws before the walk. Beautify says Paste CSS to format. Minify says Paste CSS to minify. The pane is cleared. The page does not fetch a URL and does not validate against a CSS grammar.
Rules and limitations
Beautify indents with 2 spaces by default or 4 spaces when that option is selected. Semicolon-terminated declarations gain a space after the colon. A declaration closed only by } is flushed raw, with no semicolon added. Block comments are removed in both modes.
Minify collapses the sheet to one line and turns ;} into }. Quoted semicolons are not protected. Empty input errors and clears the pane. Download output saves css-beautifier.txt. The indent menu does not rerun.
Common problems
If the last property lost its space and its semicolon, the source had no semicolon before the brace. Add one and run Beautify again if you want color: #111; rather than color:#111.
If a quoted semicolon broke a declaration in half, the walk treated that semicolon as syntax. Take the string out, or fix the line after the run. A missing comment closer can also attach the rest of the comment to the next declaration.
Frequently asked questions
Which indent sizes are offered?
2 spaces and 4 spaces, and only while Beautify is selected. 2 spaces is the initial choice. Minify ignores indent. There is no tab and no custom width.
Why is color:#111 missing a semicolon in the sample?
The sample's color declaration has no semicolon before the brace. Beautify only restyles declarations that hit a semicolon. The brace path writes the buffer as it stands.
Do comments survive?
Block comments are removed in Beautify and in Minify. An unclosed /* stays, because the remover only deletes a comment that reaches */. // is not treated as a comment.
What does Download output save?
css-beautifier.txt. The bytes are the beautified or minified text from the last success. Rename the file if you need a .css suffix.
Is my input uploaded or saved?
This tool processes input in your browser and does not save its input or output to local storage. Copy and download are user actions. The site uses analytics for page and action metadata and may use ads and production error reporting; see the Privacy Policy for those services.
About this tool
Maintained by Toolbench. For large or deeply nested files, split the input into smaller batches and verify representative results before using them in an import or application. Report reproducible problems through Contact.
Next steps
Related tools
Continue the workflow with nearby tools for formatting, publishing, debugging, or follow-up checks.
HTML Beautifier
Reindent HTML with 2 spaces, 4 spaces, or a tab.
Open HTML BeautifierColor Converter
Convert a color between HEX, RGB, and HSL.
Open Color ConverterColor Palette Generator
Build hue schemes from one hex color.
Open Color Palette GeneratorMarkdown to HTML
Turn Markdown into HTML as you type, with an optional rendered preview.
Open Markdown to HTMLTrust
Policies, contact, and answers
Clear pages for how Toolbench works, what we collect, and how to reach us.