color-named
Require (where possible) or disallow named colors.
a { color: black }/** ↑ * This named color */Use this rule to enforce a convention. CSS has a fixed set of named colors, e.g. black for #000. Choose one for consistency.
This rule ignores $sass and @less variable syntaxes.
This rule supports up to 2 message arguments: the disallowed named color, or a color and its named equivalent.
Options
Section titled “Options”"always-where-possible"
Section titled “"always-where-possible"”Colors must always, where possible, be named.
{ "color-named": "always-where-possible"}This will complain if a hex (3, 4, 6 and 8 digit), rgb(), rgba(), hsl(), hsla(), hwb() or gray() color can be represented as a named color.
The following patterns are considered problems:
a { color: #000; }a { color: #f000; }a { color: #ff000000; }a { color: rgb(0, 0, 0); }a { color: rgb(0%, 0%, 0%); }a { color: rgba(0, 0, 0, 0); }a { color: hsl(0, 0%, 0%); }a { color: hwb(0, 0%, 100%); }a { color: gray(0); }The following patterns are not considered problems:
a { color: black; }a { color: rgb(10, 0, 0); }a { color: rgb(0, 0, 0, 0.5); }"never"
Section titled “"never"”Colors must never be named.
{ "color-named": "never"}The following patterns are considered problems:
a { color: black; }a { color: white; }The following patterns are not considered problems:
a { color: #000; }a { color: rgb(0, 0, 0); }a { color: var(--white); }Optional secondary options
Section titled “Optional secondary options”ignore
Section titled “ignore”{ "ignore": ["array", "of", "options"] }"inside-function"
Section titled “"inside-function"”Ignore colors that are inside a function.
Given:
{ "color-named": ["never", { "ignore": ["inside-function"] }]}The following patterns are not considered problems:
a { color: map-get($color, blue);}a { background-image: url(red);}ignoreFunctions
Section titled “ignoreFunctions”{ "ignoreFunctions": ["array", "of", "functions", "/regex/"] }Ignore named colors within the specified functions.
Given:
{ "color-named": ["never", { "ignoreFunctions": ["var", "/^--/"] }]}The following patterns are not considered problems:
a { color: var(--foo, red); }a { color: --foo(red); }ignoreProperties
Section titled “ignoreProperties”{ "ignoreProperties": ["array", "of", "properties", "/regex/"] }Given:
{ "color-named": ["never", { "ignoreProperties": ["/^my-/", "composes"] }]}The following patterns are not considered problems:
a { my-property: red;}a { my-other-property: red;}a { composes: red from './index.css';}