LinuxCommandLibrary

csslint

Lint CSS code for errors and style

TLDR

Lint a single CSS file

$ csslint [file.css]
copy

Lint multiple CSS files
$ csslint [file1.css file2.css ...]
copy

List all possible style rules
$ csslint --list-rules
copy

Treat certain rules as errors (which results in a non-zero exit code)
$ csslint --errors=[errors,universal-selector,imports] [file.css]
copy

Treat certain rules as warnings
$ csslint --warnings=[box-sizing,selector-max,floats] [file.css]
copy

Ignore specific rules
$ csslint --ignore=[ids,rules-count,shorthand] [file.css]
copy

SYNOPSIS

csslint [options] <file> [<file>...]
cat <file> | csslint [options] -

PARAMETERS

--format=<format>
    Specifies the output format for the linting results. Common formats include text (default), compact, csslint-xml, checkstyle-xml, and json.

--warnings=<rules>
    A comma-separated list of rules that should be treated as warnings. This overrides the default severity of specified rules.

--errors=<rules>
    A comma-separated list of rules that should be treated as errors. This overrides the default severity of specified rules.

--rules=<rules>
    A comma-separated list of rules to explicitly enable or disable. Rules can be disabled by prefixing their name with a hyphen (e.g., -box-model).

--quiet
    Suppresses all output if no errors or warnings are found. Useful for scripting in CI/CD pipelines.

--help
    Displays a help message with available options and usage examples.

--version
    Prints the version number of csslint.

-
    Reads CSS input from standard input (stdin) instead of a file.

DESCRIPTION

csslint is a command-line tool that performs static analysis on Cascading Style Sheets (CSS) code.

It helps developers identify potential errors, inconsistencies, inefficiencies, and deviations from coding conventions. By providing configurable rules, it allows teams to enforce coding standards and improve the maintainability, browser compatibility, and performance of their stylesheets. csslint can be integrated into build processes, used as a pre-commit hook, or run standalone to validate CSS files.

CAVEATS

csslint has not been actively maintained for several years, which means it may not fully support newer CSS features (like advanced Flexbox/Grid properties, custom properties, or newer at-rules). For modern CSS development, more actively maintained linters like Stylelint are generally recommended due to their comprehensive rule sets, plugin ecosystem, and community support.

CONFIGURING RULES INLINE

Specific csslint rules can be enabled or disabled directly within CSS files using special comments. For example, to disable the 'box-model' rule for a section of code, you can use /* csslint box-model:false */.

EXIT CODES

csslint returns a non-zero exit code if any errors are detected during the linting process. This behavior is crucial for integrating csslint into automated build systems and Continuous Integration (CI/CD) pipelines, allowing builds to fail when code quality issues are found.

HISTORY

csslint was created by Nicholas C. Zakas and Nicole Sullivan in 2011. It emerged as an early tool to provide programmatic enforcement of CSS coding standards and to identify common pitfalls and best practice violations. While it gained significant popularity in the early 2010s, its development has slowed considerably in recent years, leading to the rise of more modern and actively developed alternatives in the CSS linting ecosystem.

SEE ALSO

stylelint(1), jshint(1), eslint(1), htmlhint(1)

Copied to clipboard