Skip to content

Commit a8df653

Browse files
svgeesusclaude
andcommitted
[css-color-4] Define color value comparison algorithm #13157
Add a new "Comparing <<color>> Values" section immediately before "Color Interpolation", defining when two <<color>> values are "equivalent colors". The algorithm covers three cases: same color space (component-by-component with epsilon, none only equals none), different color spaces with a missing component (not equal), and different color spaces with no missing components (convert to oklab, compare with epsilon). Legacy sRGB syntaxes (rgb(), hsl(), hwb(), hex, named, system colors) are normatively declared to share the srgb color space. Used by style() container queries and CSS Transitions to detect color changes. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4ead88d commit a8df653

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

.claude/settings.local.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"WebFetch(domain:github.com)",
5+
"WebFetch(domain:api.github.com)",
6+
"Bash(xargs grep:*)"
7+
]
8+
}
9+
}

css-color-4/Overview.bs

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4777,6 +4777,81 @@ where |src| and |dest| are <em>different</em>:
47774777
</div>
47784778

47794779

4780+
<!--
4781+
██████ ███████ ██ ██ ████████ ███ ████████ ████████
4782+
██ ██ ██ ██ ███ ███ ██ ██ ██ ██ ██ ██
4783+
██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██
4784+
██ ██ ██ ██ ███ ██ ██████ ██ ██ ████████ ██████
4785+
██ ██ ██ ██ ██ ██ █████████ ██ ██ ██
4786+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
4787+
██████ ███████ ██ ██ ████████ ██ ██ ██ ██ ████████
4788+
-->
4789+
4790+
<h2 id="comparing-color-values">
4791+
Comparing <<color>> Values</h2>
4792+
4793+
Two <<color>> values are <dfn export>equivalent colors</dfn>
4794+
when they compare as equal using the algorithm below.
4795+
This comparison is used,
4796+
for example,
4797+
by ''style()'' container queries [[CSS-CONDITIONAL-5]]
4798+
and by CSS Transitions [[CSS-TRANSITIONS-1]]
4799+
to determine whether a color value has changed.
4800+
4801+
Given two <<color>> values <var>C1</var> and <var>C2</var>,
4802+
they are [=equivalent colors=] if and only if
4803+
the following algorithm returns true:
4804+
4805+
<ol>
4806+
<li>
4807+
For each of <var>C1</var> and <var>C2</var>,
4808+
convert any [=powerless component=]s to [=missing component=]s.
4809+
</li>
4810+
<li>
4811+
If <var>C1</var> and <var>C2</var> share the same <<color-space>>:
4812+
<ol>
4813+
<li>
4814+
Compare their components one by one,
4815+
including the alpha channel.
4816+
A [=missing component=] is only equal to
4817+
another [=missing component=].
4818+
Two numeric components are considered equal
4819+
if they differ by no more than a small
4820+
implementation-defined ε.
4821+
</li>
4822+
<li>
4823+
Return true if and only if
4824+
all components compare as equal.
4825+
</li>
4826+
</ol>
4827+
</li>
4828+
<li>
4829+
Otherwise, <var>C1</var> and <var>C2</var> are in different <<color-space>>s.
4830+
If either color has at least one [=missing component=],
4831+
return false.
4832+
</li>
4833+
<li>
4834+
Otherwise, neither color has any [=missing component=].
4835+
Convert both <var>C1</var> and <var>C2</var> to ''oklab'',
4836+
then return true if and only if
4837+
all components (including alpha) of the converted colors
4838+
compare as equal,
4839+
using an implementation-defined ε as in step 2.
4840+
</li>
4841+
</ol>
4842+
4843+
Note: Two colors that are expressed in different <<color-space>>s
4844+
but are colorimetrically identical—for example,
4845+
''red'' and ''color(srgb 1 0 0)''—are [=equivalent colors=]
4846+
by step 4 of this algorithm,
4847+
since they convert to the same ''oklab'' value.
4848+
4849+
For the purposes of this comparison,
4850+
''rgb()'', ''rgba()'', ''hsl()'', ''hsla()'', ''hwb()'',
4851+
[=hex colors=], [=named colors=], and [=system colors=]
4852+
are all considered to be in the ''srgb'' <<color-space>>.
4853+
4854+
47804855
<!--
47814856
████ ██ ██ ████████ ████████ ████████ ████████ ███████ ██ ███ ████████ ████████
47824857
██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
@@ -7907,7 +7982,12 @@ Changes</h2>
79077982
<a href="https://www.w3.org/TR/2025/CRD-css-color-4-20250424/">Candidate Recommendation Draft of 24 April 2025</a></h3>
79087983

79097984
<ul>
7910-
<!-- to 13 April 2026 -->
7985+
<!-- to 14 April 2026 -->
7986+
<li>Added a new section defining when two <<color>> values are [=equivalent colors=],
7987+
covering same-color-space component comparison, the treatment of [=missing component=]s,
7988+
and cross-color-space comparison via ''oklab''.
7989+
(<a href="https://github.com/w3c/csswg-drafts/issues/13157">Issue 13157</a>)
7990+
</li>
79117991
<li>Clarified in the main Color interpolation section that, if the hue interpolaton method is not specified, shorter is the default. (This was already specified in the Hue Interpolation section).
79127992
(<a href="https://github.com/w3c/csswg-drafts/issues/13788">Issue 13788</a>)
79137993
</li>

0 commit comments

Comments
 (0)