Skip to content

[css-color-5] Tests for resolved alpha(from currentcolor ...) values have incorrect serialization #60611

Closed

Description

@kbhomes

See the tests here in alpha-color-computed.html. An example test case:

test_currentcolor_alpha("alpha(from currentcolor / 0.5)", "color(srgb 1 0 0 / 0.5)", "red");

This test gives the element color: red and then specifies background-color: alpha(from currentcolor / 0.5). It then asserts a resolved value for background-color of color(srgb 1 0 0 / 0.5). But my reading of the Level 4 and 5 specifications is that the actual resolved value should be rgba(255, 0, 0, 0.5). Here's how I'm getting that:

Specified Value

The specified value is just alpha(from currentcolor / 0.5) on the background-color property.

Computed Value

From Level 5 § 10.2. Resolving Relative Color Syntax, it says:

Otherwise (if currentColor was used in the function), the computed value is the Relative Color Syntax function with the origin parameter resolved according to CSS Color 4 §  15. Resolving Values, thus preserving inheritance into child elements.

And since currentcolor computes to itself, then the the computed value of this color is the same thing, the relative color function alpha(from currentcolor / 0.5).

Used/Resolved Value

To find the used/resolved value, it needs to resolve the currentcolor. In Level 4 § 15.5. Resolving other colors, it says:

In the color property, the used value of currentcolor is the resolved inherited value. In any other property, its used value is the used value of the color property on the same element.

So the used/resolved value of currentcolor in background-color is just the resolved value of the color property, which is the sRGB color value that serializes to rgb(255, 0, 0). With that, we can resolve the function per Level 5 § 10.2. Resolving Relative Color Syntax:

If all parameters resolve to the corresponding colors in their respective color spaces, the computed value is the absolute value, in the specified RCS color space, resolved according to CSS Color 4 §  15. Resolving Values.

For the alpha() function, the absolute value and color space are defined per Level 5 § 4.10. Relative Alpha Colors as:

The color components of the origin color are unchanged, the alpha component is modified or replaced. The result of this function is in the color space of the origin color.

This means that the used/resolved value of alpha(from currentcolor / 0.5) is the origin color (resolved to the sRGB color represented by rgb(255, 0, 0)) in its original color space (sRGB) with the modified alpha component (0.5). As an sRGB color value, this should serialize as rgba(255, 0, 0, 0.5).


I believe that according to Level 4 § 15.4. Resolving values of the color() function, the only way to serialize a resolved color value to color(srgb ...) would be if the specified value itself was color(srgb ...). That's not the case in these alpha(from currentcolor ...) teset cases, and therefore the color() function should not be appearing in the serialization.


One note on the specification is that Level 5 § 10.2. Resolving Relative Color Syntax only refers to the "computed value" stage when I think it should be clearer about computed vs. used/resolved.

Activity

  1. kbhomes commented on Jun 13, 2026

    @kbhomes
    ContributorAuthor

    Tagging a couple people I've seen on similar color issues / PRs that might be able to look at this and let me know if I missed something here: @romainmenke @weinig

    (I was working on implementing the alpha() function for Firefox but identified this test issue. If the tests are indeed wrong and should be serializing the way I've described it, I can fix them upstream in Firefox.)

  2. romainmenke commented on Jun 14, 2026

    @romainmenke
    Contributor

    I agree that these tests are incorrect and inconsistent.

    @weinig filed a spec issue: w3c/csswg-drafts#13992

  3. kbhomes commented on Jun 15, 2026

    @kbhomes
    ContributorAuthor

    Going to close this issue, w3c/csswg-drafts#13994 is the better issue for this. And I realize now that I entirely missed the existing Level 5 § 11.3. Serializing Relative Color Functions section, which would imply that the "natural" serialization is actually that alpha(from ...) should always serialize using the color() syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions