Skip to content

[css-color-5] Clarification needed on type of r, g, b constants in "relative color syntax" for rgb() #6044

Closed
@weinig

Description

@weinig

In CSS Color 5's Relative color syntax, https://drafts.csswg.org/css-color-5/#relative-RGB, the spec is inconsistent on the types/semantics for the r, g, and b, constants. The normative text says "r", "g", and "b" are percentages ("r is a that corresponds to the origin color’s red channel after its conversion to sRGB"), but in Example 13, it is intermixing them with non-percentages:

    rgb(from indianred 255 g b)

It seems like this should resolve to

    rgb(255 36.0784% 36.0784%)

which is invalid.

In the investigative implementation in WebKit, to keep the example working, I implemented it to assume that "r", "g", and "b" can either be numbers or percentages, but they all have to be the same and match the constants as well. So in the example above, since the first parameter is 255, it forces "g" and "b" to use their numeric forms, and therefore resolves to:

    rgb(255 92, 92)

Which is what the example says is the result.

This leaves a weird case of no numeric constant being used for any parameter, like:

    rgb(from indianred calc(r+1) calc(g+1) calc(b+1))

in which case we need some default type. I have picked percentages, since that is what the spec text currently says is the type, but I am not sure if that is desirable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions