Skip to content

Commit f5a104b

Browse files
committed
[css-color-6] Make contrast-color() candidates optional
Also move grammar above description of syntax, and some minor prose cleanup
1 parent 36594e9 commit f5a104b

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

css-color-6/Overview.bs

+28-15
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,40 @@ Introduction {#intro}
5252
https://caniuse.com/mdn-css_types_color_color-contrast
5353
-->
5454

55-
Selecting the most contrasting color: the ''contrast-color()'' function {#colorcontrast}
55+
Computing a sufficiently contrasting color: the ''contrast-color()'' function {#colorcontrast}
5656
========================================================================================
5757

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 <a href="https://www.w3.org/TR/WCAG21/#contrast-minimum">luminance contrast</a> [[!WCAG21]].
58+
The purpose of this function is to generate sufficiently contrasting colors from other colors,
59+
without authors having to compute them manually.
6260

63-
It <a href="#winner">returns</a> 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+
<pre class='prod'>
64+
<dfn>contrast-color()</dfn> = contrast-color( <<color>> [ vs <<color>>#{2,} ]? [ to [<<number>> | AA | AA-large | AAA | AAA-large]]? )
65+
</pre>
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 <a href="https://www.w3.org/TR/WCAG21/#contrast-minimum">luminance contrast</a> [[!WCAG21]]
74+
is provided after a ''contrast-color()/to'' keyword.
75+
76+
If a target contrast is specified,
77+
the <a href="#winner">returned color</a> 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.
6782

6883
The single color is separated from the list
6984
with the keyword <css>vs</css>
7085
and the target contrast, if present, is separated from the list
7186
with the keyword <css>to</css>.
7287

73-
<pre class='prod'>
74-
<dfn>contrast-color()</dfn> = contrast-color( <<color>> vs <<color>>#{2,} [ to [<<number>> | AA | AA-large | AAA | AAA-large]]? )
75-
</pre>
88+
7689

7790
The keyword <dfn value for="contrast-color()">AA</dfn> is equivalent to ''4.5'',
7891
<dfn value for="contrast-color()">AA-large</dfn> is equivalent to ''3'',
@@ -173,10 +186,10 @@ Selecting the most contrasting color: the ''contrast-color()'' function {#colorc
173186

174187
</div>
175188

176-
The colors in the list (after the keyword vs) are tested sequentially,
189+
The candidate colors are tested sequentially,
177190
from left to right;
178191
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.
180193

181194
List traversal is terminated once the target contrast has been met or exceeded.
182195

@@ -260,7 +273,7 @@ Selecting the most contrasting color: the ''contrast-color()'' function {#colorc
260273

261274
the contrast with cadetblue is <strong>1.97</strong>
262275
while the contrast with hsl(200 83% 23%) is <strong>6.09</strong>
263-
which exceeds 4.5, the value for 'AA';
276+
which exceeds 4.5, the value for ''AA'';
264277
so it has the computed value of the resolved hsl function:
265278

266279
<pre class="lang-css">

0 commit comments

Comments
 (0)