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> [<FILE2> ...]

PARAMETERS

--help
    Display usage information

--version
    Show CSSLint version

--format=FORMAT
    Output format: text (default), compact, lint-xml, csslint-xml, json

--quiet
    Only report error count

--errors
    Report only errors, ignore warnings

--warnings
    Report only warnings, ignore errors

--list-rules
    List all available rules

--rules=RULES
    Apply specific rules (comma-separated, e.g. errors,known-properties)

--exclude-list=RULES
    Exclude specific rules (comma-separated)

--ignore=RULES
    Alias for --exclude-list

--help-rules
    List rules with descriptions

DESCRIPTION

CSSLint is a command-line tool for analyzing CSS code to detect errors, potential problems, and violations of best practices. Installed via npm install -g csslint, it helps developers maintain clean, efficient stylesheets by flagging issues like duplicate properties, inefficient selectors, or non-standard rules.

Run it on CSS files to get reports in various formats. It categorizes issues into errors (likely bugs) and warnings (style improvements). Highly configurable via rule lists, allowing focus on specific concerns. Ideal for CI/CD pipelines, pre-commit hooks, or manual checks.

Though effective, note it's somewhat dated; modern alternatives like Stylelint offer broader support including preprocessors.

CAVEATS

Node.js dependency; deprecated in favor of Stylelint. Limited preprocessor support. No stdin reading.

RULE CATEGORIES

Errors: syntax bugs, invalid rules. Warnings: performance, maintainability issues like adjoining-classes, box-model.

USAGE EXAMPLE

csslint --format=compact style.css for concise output.

HISTORY

Developed by Nicholas C. Zakas in 2011 as part of Yahoo's YUI library. Evolved into standalone tool. Maintained until ~2017; last major release v1.0.5. Widely used in early CSS linting era.

SEE ALSO

Copied to clipboard