1 | # color-function-notation
|
2 |
|
3 | Specify modern or legacy notation for applicable color-functions.
|
4 |
|
5 |
|
6 | ```css
|
7 | a { color: rgb(0 0 0 / 0.2) }
|
8 | /** ↑
|
9 | * This notation */
|
10 | ```
|
11 |
|
12 | Modern color-functions use a comma-free syntax because functions in CSS are used to group/name a syntax chunk. They should work by the same rules that CSS grammar does in general: values are optional and re-orderable when possible, space-separated, and commas are used to separate repetitions only.
|
13 |
|
14 | For legacy reasons, `rgb()` and `hsl()` also supports an alternate syntax that separates all of its arguments with commas. Also for legacy reasons, the `rgba()` and `hsla()` functions exist using the same comma-based syntax.
|
15 |
|
16 | The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix some of the problems reported by this rule when the primary option is `"modern"`.
|
17 |
|
18 | ## Options
|
19 |
|
20 | `string`: `"modern"|"legacy"`
|
21 |
|
22 | ### `"modern"`
|
23 |
|
24 | Applicable color-functions _must always_ use modern notation.
|
25 |
|
26 | The following patterns are considered violations:
|
27 |
|
28 |
|
29 | ```css
|
30 | a { color: rgb(0, 0, 0) }
|
31 | ```
|
32 |
|
33 |
|
34 | ```css
|
35 | a { color: rgba(12, 122, 231, 0.2) }
|
36 | ```
|
37 |
|
38 |
|
39 | ```css
|
40 | a { color: hsla(270, 60%, 50%, 15%) }
|
41 | ```
|
42 |
|
43 |
|
44 | ```css
|
45 | a { color: hsl(.75turn, 60%, 70%) }
|
46 | ```
|
47 |
|
48 | The following patterns are _not_ considered violations:
|
49 |
|
50 |
|
51 | ```css
|
52 | a { color: rgb(0 0 0) }
|
53 | ```
|
54 |
|
55 |
|
56 | ```css
|
57 | a { color: rgb(12 122 231 / 0.2) }
|
58 | ```
|
59 |
|
60 |
|
61 | ```css
|
62 | a { color: hsl(270 60% 50% / 15%) }
|
63 | ```
|
64 |
|
65 |
|
66 | ```css
|
67 | a { color: hsl(.75turn 60% 70%) }
|
68 | ```
|
69 |
|
70 | ### `"legacy"`
|
71 |
|
72 | Applicable color-functions _must always_ use the legacy notation.
|
73 |
|
74 | The following patterns are considered violations:
|
75 |
|
76 |
|
77 | ```css
|
78 | a { color: rgb(0 0 0) }
|
79 | ```
|
80 |
|
81 |
|
82 | ```css
|
83 | a { color: rgb(12 122 231 / 0.2) }
|
84 | ```
|
85 |
|
86 |
|
87 | ```css
|
88 | a { color: hsl(270 60% 50% / 15%) }
|
89 | ```
|
90 |
|
91 |
|
92 | ```css
|
93 | a { color: hsl(.75turn 60% 70%) }
|
94 | ```
|
95 |
|
96 | The following patterns are _not_ considered violations:
|
97 |
|
98 |
|
99 | ```css
|
100 | a { color: rgb(0, 0, 0) }
|
101 | ```
|
102 |
|
103 |
|
104 | ```css
|
105 | a { color: rgba(12, 122, 231, 0.2) }
|
106 | ```
|
107 |
|
108 |
|
109 | ```css
|
110 | a { color: hsla(270, 60%, 50%, 15%) }
|
111 | ```
|
112 |
|
113 |
|
114 | ```css
|
115 | a { color: hsl(.75turn, 60%, 70%) }
|
116 | ```
|