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
<pre class='prod'>
64-
<dfn>contrast-color()</dfn> = contrast-color( <<color>> [ vs <<color>>#{2,} ]? [ to [<<number>> | AA | AA-large | AAA | AAA-large]]? )
64+
<dfn>contrast-color()</dfn> = contrast-color( <<color>> [ vs <<color>>#{2,} ]? [ to <<target-contrast>>]? )
65+
<dfn><<target-contrast>></dfn> = wcag2([<<number>> | [ aa | aaa ] && large? ])
6566
</pre>
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 <css>to</css>.
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 <dfn value for="contrast-color()">AA</dfn> is equivalent to ''4.5'',
91-
<dfn value for="contrast-color()">AA-large</dfn> is equivalent to ''3'',
92-
<dfn value for="contrast-color()">AAA</dfn> is equivalent to ''7'', and
93-
<dfn value for="contrast-color()">AAA-large</dfn> 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
<h3 id="luminance-contrast">
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
<div class="example">
163-
<pre class="lang-css">contrast-color(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA)</pre>
166+
<pre class="lang-css">contrast-color(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to wcag2(aa))</pre>
164167

165168
The calculation is as follows:
166169
* <span class="swatch" style="--color: wheat"></span> wheat (#f5deb3), the background, has relative luminance 0.749
@@ -177,7 +180,7 @@ Computing a sufficiently contrasting color: the ''contrast-color()'' function {#
177180
</div>
178181

179182
<div class="example">
180-
<pre class="lang-css">contrast-color(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to 5.8)</pre>
183+
<pre class="lang-css">contrast-color(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to wcag2(5.8))</pre>
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
<div class="example">
208-
<pre class="lang-css">contrast-color(wheat vs bisque, darkgoldenrod, olive to AA)</pre>
211+
<pre class="lang-css">contrast-color(wheat vs bisque, darkgoldenrod, olive to wcag2(AA))</pre>
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
<pre class="lang-css">
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
</pre>
273276

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

291294
<pre class="lang-css">
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
</pre>
294297

295298
has the computed value
296299

297300
<pre class="lang-css">
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
</pre>
300303

301304
</div>

0 commit comments

Comments
 (0)