Skip to content

alpha-value-notation

Reports the alpha value of rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch() or color() written as a number (/ 0.5), also the fourth argument of the comma form of rgba() and hsla(), on the function name. A percentage is not reported.

An alpha value can be a number or a percentage, and a file that mixes both makes the reader convert in the head: 0.5 and 50% are the same. The rule keeps one notation, the percentage, which reads as a share of opacity and matches how the channels of hsl() are written.

To fix, write / 50% instead of / 0.5.

Reported
a { color: rgba(0, 0, 0, 0.5); }
...
d { color: rgb(0 0 0 / 0.5); }
e { color: hsl(120deg 50% 50%); }
...
h { color: rgb(0 0 0 / 50%); }
i { color: hsl(120 50% 50% / 0.5); }
j { color: rgb(var(--x), 0.5); }
k { color: rgb(var(--x) / 0.5); }
...
m { color: oklch(50% 0.2 120deg / 50%); }
n { color: rgb(0 0 0); }
o { color: hsla(var(--h), var(--s), var(--l), 1); }
css:
lint:
rules:
alpha-value-notation: warn # off (default), warn, error
less:
lint:
rules:
alpha-value-notation: warn # off (default), warn, error
scss:
lint:
rules:
alpha-value-notation: warn # off (default), warn, error

Enabled by the presets: css/stylelint-standard.

Suppress one line with sudsy-disable-next-line alpha-value-notation in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
stylelint alpha-value-notation full