Formatting
csskit comes with a CSS code formatter built in. Use csskit fmt to format your CSS files for better readability and consistency.
Quick Start
Format a single file:
csskit fmt styles.cssFormat multiple files:
csskit fmt styles.css theme.css components.cssFormat from stdin (useful for piping):
cat styles.css | csskit fmt
echo "body{margin:0}" | csskit fmtBy default, csskit fmt writes formatted output to stdout. Use -o to write to a file:
csskit fmt input.css -o output.cssOptions
Tab Expansion
By default csskit fmt will use tabs for indentation. If you prefer spaces over tabs, add --expand-tab N and it will expand tabs into N space characters:
csskit fmt --expand-tab 2 styles.cssQuote Style
By default csskit fmt will use double quotes for strings. If you prefer single quote characters over double quotes, add --single-quotes:
csskit fmt --single-quotes styles.cssExample:
Input:
div {
content: "hello world";
font-family: "Arial", "Helvetica", sans-serif;
}Output:
div {
content: "hello world";
font-family: 'Arial', 'Helvetica', sans-serif;
}Check Mode
Use --check to verify if files need formatting without making changes. This is useful in CI/CD pipelines:
csskit fmt --check styles.cssThis will:
- Exit with status code 0 if no changes needed
- Exit with non-zero status code if formatting would change the file
- Report which changes would be made without writing them
Example in CI:
# Fail the build if CSS isn't formatted
csskit fmt --check src/**/*.cssProcessing Content Directly
Use --content (or -c) to format CSS content directly from the command line:
csskit fmt -c "body{margin:0;padding:0}"Output:
body {
margin: 0;
padding: 0;
}