@@ -52,27 +52,40 @@ Introduction {#intro}
52
52
https://caniuse.com/mdn-css_types_color_color-contrast
53
53
-->
54
54
55
- Selecting the most contrasting color: the ''contrast-color()'' function {#colorcontrast}
55
+ Computing a sufficiently contrasting color: the ''contrast-color()'' function {#colorcontrast}
56
56
========================================================================================
57
57
58
- This function takes, firstly, a single color
59
- (typically a background, but not necessarily),
60
- secondly, a list of two or more colors,
61
- and thirdly, an optional target
luminance contrast [[!WCAG21]] .
58
+ The purpose of this function is to generate sufficiently contrasting colors from other colors,
59
+ without authors having to compute them manually.
62
60
63
- It
returns the first color in the list
64
- to meet or exceed the specified target contrast
65
- or, if no target is given,
66
- the color in the list with the greatest contrast.
61
+ Its syntax is:
62
+
63
+
64
+ contrast-color() = contrast-color( <> [ vs <> #{2,} ]? [ to [<> | AA | AA-large | AAA | AAA-large]]? )
65
+
66
+
67
+ The only mandatory argument is the first color, which is the color to be contrasted,
68
+ typically (but not necessarily) a background color.
69
+
70
+ An optional list of color candidates is provided after a ''vs'' keyword.
71
+ If no candidates are provided, the default candidates are used: ''white, black'' .
72
+
73
+ An optional target
luminance contrast [[!WCAG21]]
74
+ is provided after a ''contrast-color()/to'' keyword.
75
+
76
+ If a target contrast is specified,
77
+ the
returned color is the first color candidate that meets or exceeds the target contrast.
78
+ If no target is given,
79
+ the color candidate with the greatest contrast is returned.
80
+ If multiple candidates have the same contrast,
81
+ the one that comes earliest in the list is returned.
67
82
68
83
The single color is separated from the list
69
84
with the keyword vs
70
85
and the target contrast, if present, is separated from the list
71
86
with the keyword to .
72
87
73
-
74
- contrast-color() = contrast-color( <> vs <> #{2,} [ to [<> | AA | AA-large | AAA | AAA-large]]? )
75
-
88
+
76
89
77
90
The keyword AA is equivalent to ''4.5'' ,
78
91
AA-large is equivalent to ''3'' ,
@@ -173,10 +186,10 @@ Selecting the most contrasting color: the ''contrast-color()'' function {#colorc
173
186
174
187
175
188
176
- The colors in the list (after the keyword vs) are tested sequentially,
189
+ The candidate colors are tested sequentially,
177
190
from left to right;
178
191
a color is the temporary winner
179
- if it has the highest contrast of all those tested so far.
192
+ if it has the highest contrast of all those tested so far.
180
193
181
194
List traversal is terminated once the target contrast has been met or exceeded.
182
195
@@ -260,7 +273,7 @@ Selecting the most contrasting color: the ''contrast-color()'' function {#colorc
260
273
261
274
the contrast with cadetblue is 1.97
262
275
while the contrast with hsl(200 83% 23%) is 6.09
263
- which exceeds 4.5, the value for 'AA ' ;
276
+ which exceeds 4.5, the value for ''AA' ' ;
264
277
so it has the computed value of the resolved hsl function:
265
278
266
279
0 commit comments