Skip to content

[css-color-4] Serialization/normalization of color() (and other advanced color functions) #4826

@tabatkins

Description

@tabatkins

All of the sRGB-compatible color functions (everything from Color 3) eagerly normalize into an sRGB tuple, and serialize with rgb(), so you lose information about whether it was originally written as #000, hsl(), etc. This lets UAs eagerly translate it into an efficient internal format (a 32-bit int) and not worry about additional details.

How should we serialize color(), lab(), etc? Chrome is looking into implementing, and is currently planning to eagerly convert these into extended-sRGB, likely stored as four 32-bit floats. Which serialization form should we prefer?

Reasonable options seem to be:

  • rgb(), with decimals and values outside of [0,255] to represent the extended-sRGB value. Benefit: should be backwards-compatible with at least some existing color code; doesn't require us to distinguish between legacy color formats (which must stay serializing as rgb()) and newer ones. Cons: requires us to define that rgb() supports extended-sRGB.
  • color(), with some arbitrary choice of colorspace. Benefit: perhaps clearer, especially if it happens to match the colorspace the author chose. Downside: requires us to carry an extra bit around for whether the color was in a legacy format or not; might still be an unexpected result if you used a different colorspace.
  • lab(), same benefits/downsides as color(), but maybe more appropriate as a "universal" serialization format for higher-def colors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions