Skip to content

Commit 3e46e26

Browse files
committed
[css-color-6] syntax to specify contrast algorithm for contrast-color(), following WG resolution
Closes #7356
1 parent f5a104b commit 3e46e26

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

css-color-6/Overview.bs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ Computing a sufficiently contrasting color: the ''contrast-color()'' function {#
6161
Its syntax is:
6262

6363
64-
contrast-color() = contrast-color( <> [ vs <>#{2,} ]? [ to [<> | AA | AA-large | AAA | AAA-large]]? )
64+
contrast-color() = contrast-color( <> [ vs <>#{2,} ]? [ to <>]? )
65+
<> = wcag2([<> | [ aa | aaa ] && large? ])
6566
6667

6768
The only mandatory argument is the first color, which is the color to be contrasted,
@@ -85,12 +86,14 @@ Computing a sufficiently contrasting color: the ''contrast-color()'' function {#
8586
and the target contrast, if present, is separated from the list
8687
with the keyword to.
8788

89+
The target contrast is specified by providing a function for the algorithm used
90+
(currently only [WCAG 2.1](#luminance-contrast) is supported )
91+
with the contrast ratio as the argument.
8892

89-
90-
The keyword AA is equivalent to ''4.5'',
91-
AA-large is equivalent to ''3'',
92-
AAA is equivalent to ''7'', and
93-
AAA-large is equivalent to ''4.5'' .
93+
For ''wcag2()'', ''aa'' is equivalent to ''4.5'',
94+
''aa large'' (or ''large aa'') is equivalent to ''3'',
95+
''aaa'' is equivalent to ''7'',
96+
and ''aaa large'' (or ''large aaa'') is equivalent to ''4.5''.
9497

9598

9699
Calculating luminance and WCAG 2.1 contrast
@@ -160,7 +163,7 @@ Computing a sufficiently contrasting color: the ''contrast-color()'' function {#
160163
https://colorjs.io/notebook/?storage=https%3A%2F%2Fgist.github.com%2Fsvgeesus%2Fec249f376fcecbaa8794f75dbfc1dacf
161164
-->
162165
163-
contrast-color(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA)
166+
contrast-color(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to wcag2(aa))
164167

165168
The calculation is as follows:
166169
* wheat (#f5deb3), the background, has relative luminance 0.749
@@ -177,7 +180,7 @@ Computing a sufficiently contrasting color: the ''contrast-color()'' function {#
177180
178181

179182
180-
contrast-color(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to 5.8)
183+
contrast-color(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to wcag2(5.8))
181184

182185
The calculation is as follows:
183186
* the relative luminances and contrast ratios are the same as the previous example.
@@ -205,7 +208,7 @@ Computing a sufficiently contrasting color: the ''contrast-color()'' function {#
205208
whichever has the higher contrast.
206209

207210
208-
contrast-color(wheat vs bisque, darkgoldenrod, olive to AA)
211+
contrast-color(wheat vs bisque, darkgoldenrod, olive to wcag2(AA))
209212

210213
The calculation is as follows:
211214
* the relative luminances and contrast ratios are the same as the previous example.
@@ -268,7 +271,7 @@ Computing a sufficiently contrasting color: the ''contrast-color()'' function {#
268271
For example, given the value
269272

270273
271-
contrast-color(rgb(179 213 230) vs cadetblue, hsl(200 83% 23%) to AA)
274+
contrast-color(rgb(179 213 230) vs cadetblue, hsl(200 83% 23%) to wcag2(AA))
272275
273276

274277
the contrast with cadetblue is 1.97
@@ -289,13 +292,13 @@ Computing a sufficiently contrasting color: the ''contrast-color()'' function {#
289292
the value
290293

291294
292-
contrast-color(currentColor vs hsl(200 83% 23%), purple to AA)
295+
contrast-color(currentColor vs hsl(200 83% 23%), purple to wcag2(AA))
293296
294297

295298
has the computed value
296299

297300
298-
contrast-color(currentColor vs rgb(10 75 107), rgb(128 0 128) to 4.5)
301+
contrast-color(currentColor vs rgb(10 75 107), rgb(128 0 128) to wcag2(4.5))
299302
300303

301304

0 commit comments

Comments
 (0)