Skip to content

[css-color] Custom color palettes #5730

@Crissov

Description

@Crissov

The @color-profile at-rule currently has two possible descriptors, src and rendering-intent. It also has a name that is either device-cmyk or a custom <dashed-ident>. This name will be used to specify custom color profiles inside the color() function.

The color() function supports named colors from profiles, although this is a feature not often used in ISO 15076-1 / ICC color profile files. #817 It is unlikely that browsers will (initially) support fetching and using random ICC profiles from remote sources.
Update: If #6095 is accepted, support for color names from profiles will be removed.

I wish one could specify color palettes with named colors within CSS, e.g. for spot colors. Those would be tied to a particular color profile (and space). Therefore, custom properties would not be the proper solution, although they work:

:root {
  --my-green: color(a98-rgb 98% 1% 1%);
}
foo {
  color: var(--my-green);
}

This looks cleaner:

@color-profile a98-rgb {
  src: url("adobe.icc"); /* invalid for predefined color profiles */
  green: 96% 2% 2%; /* specify existing CSS color names as descriptors */
  --my-green: 98% 1% 1%; /* custom color name */
}
foo {
  color: color(a98-rgb green);
  background: color(a98-rgb --my-green);
}

If the default color profile could be set by an inherited property, this would look even cleaner:

:root {
  color-profile: a98-rgb; /* overrides `srgb` default */
}
foo {
  color: color(green); /* or just `green`? */
  background: color(--my-green); /* different from `var(--my-green)` */
}

Current color names are specified in the default color profile and space, i.e. sRGB. They could be overwritten, but then perhaps only be used within the color() function:

@color-profile srgb {
  green: 96% 2% 2%; /* specify existing CSS color names as descriptors */
}
foo {
  color: color(green); /* custom redefinition is used */
  background: green; /* custom redefinition is _not_ used */
}

Instead of adding descriptors to the @color-profile at-rule, there could also be a dedicated @color-palette at-rule.

@color-palette --my-palette {
  green: 96% 2% 2%; 
}
@color-profile srgb {
  src: var(--my-palette);
}

or with a dedicated palette descriptor:

@color-profile srgb {
  palette: --my-palette;
}

Except, since this at-rule would need to be independent of the color profile, it should define its colors absolutely:

@color-palette --my-palette {
  green: color(srgb 96% 2% 2%); /* equivalent to classic rgb(96% 2% 2%) */
}

Alternatively, a new @color or @color-name at-rule could be introduced to define a named color depending on the active color profile:

@color green {
  --my-palette: 1% 98% 1%;
  a98-rgb: 2% 96% 2%;
  cmyk: 60% 5% 60% 20%;
  cmykgov: 0% 0% 0% 0% 100% 0% 0%;
  monochrome: 78%;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closed as Question AnsweredUsed when the issue is more of a question than a problem, and it's been answered.css-color-5Color modification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions