Skip to main content

Synopsis

css-beautify [options] <file ...>
The css-beautify command is installed alongside js-beautify when you install the package globally:
npm install -g js-beautify
Beautified output is written to stdout by default. You can also invoke the CSS beautifier via js-beautify --type css.
Pass - as a filename to read from stdin.

Options

I/O options

FlagLong formDescription
-f--fileInput file(s). Pass - for stdin.
-r--replaceWrite output in-place, overwriting the input file.
-o--outfileWrite output to a specific file instead of stdout.
--configPath to a JSON config file.
-q--quietSuppress logging to stdout.
-h--helpShow help and exit.
-v--versionShow the version number and exit.

Indentation options

FlagLong formDefaultDescription
-s--indent-size4Number of spaces per indentation level.
-c--indent-char" "Character used for indentation.
-t--indent-with-tabsfalseIndent with tabs, overrides -s and -c.
--indent-empty-linesfalseKeep indentation on empty lines.
--editorconfigfalseUse EditorConfig to set options from .editorconfig.

Output formatting

FlagLong formDefaultDescription
-e--eolfirst newline in file, else \nLine terminator character(s).
-n--end-with-newlinefalseEnd output with a newline.
-b--brace-stylecollapseBrace placement: collapse (opening brace on same line as selector) or expand (opening brace on its own line).
-L--selector-separator-newlinetruePrint each selector in a multi-selector rule on its own line.
-N--newline-between-rulestrueAdd a blank line between CSS rules.

Examples

# Beautify from stdin to stdout
cat styles.min.css | css-beautify -

# Beautify a file, output to stdout
css-beautify styles.css

# Replace the file in-place
css-beautify --replace styles.css

# Write to a new file with 2-space indentation
css-beautify -s 2 -o dist/styles.formatted.css src/styles.css

# Expand braces and end with a newline
css-beautify --brace-style expand --end-with-newline styles.css

# Disable newline between rules
css-beautify --no-newline-between-rules styles.css

# Disable selector separator newlines
css-beautify --no-selector-separator-newline styles.css
You can also run the CSS beautifier via the main js-beautify command with the --type css flag:
js-beautify --type css styles.css