Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS Relative Color Syntax #226

Closed
nilaallj opened this issue Oct 16, 2022 · 7 comments
Closed

CSS Relative Color Syntax #226

nilaallj opened this issue Oct 16, 2022 · 7 comments
Labels
focus-area-proposal Focus Area Proposal

Comments

@nilaallj
Copy link

Description

The relative color syntax makes it possible to manipulate the channel values of any color using any color model.

Examples

:root {
 /* Defining a new color relative to a color defined in a custom property */
 --brand-clr: deeppink;
 --brand-clr-transparent: hsl(from var(--brand-clr) h s l / 0.5);
 --accent-clr: hsl(from var(--brand-clr) calc(h - 180deg) s l);

 /* The syntax also works between different color models and spaces */
 --darker-red: lch(from rgb(255 0 0) calc(l - 20%) c h);
 --pinkish-hue: oklch(from limegreen l c 10deg);
}

Rationale

Color theming is an important aspect of UI design, and being able to define relative colors would make this process much more streamlined and and less repetitive. Many developers already use Sass color functions to preprocess relative colors. There are also libraries such as Color.js which offers similar functionality.

In last year's State of CSS survey, "Functions for manipulating color values" scored high on "Features missing from CSS".

Specification

Tests

@nilaallj nilaallj added the focus-area-proposal Focus Area Proposal label Oct 16, 2022
@nt1m
Copy link
Member

nt1m commented Oct 29, 2022

See also w3c/csswg-drafts#7978

@emilio
Copy link

emilio commented Nov 3, 2022

This seems more of a new feature rather than interop?

@nilaallj
Copy link
Author

nilaallj commented Nov 3, 2022

@emilio
This is already implemented behind a flag in Safari, and has a W3C specification.

@gsnedders
Copy link
Member

This seems more of a new feature rather than interop?

There have been a variety of proposals which are new features, and we didn't exclude new features from being included. (And we did this last year, e.g. Cascade Layers.)

@foolip
Copy link
Member

foolip commented Nov 11, 2022

Color functions and related features were a common response to the State of CSS 2022 question about browser incompatibilities, see #248.

About 3% of responses mentioned color functions directly or indirectly, usually as "color function" or "color()", but also things like "display-p3", "LCH color" or "OKLab support".

There were only 6 direct mentions of relative colors, such as "css relative colors (colors math)".

This becomes difficult to untangle since we don't know how many people know that color() as spec'd does include relative colors.

Personally, I see it as a medium-to-strong signal.

@foolip
Copy link
Member

foolip commented Nov 11, 2022

In the MDN short survey on CSS & HTML, "CSS color spaces and functions (color(), lab(), gradients, etc.)" was selected by ~25% of survey takers, putting it in the top third of the 20 options. (There is some uncertainty as with any survey data.)

@nairnandu
Copy link
Contributor

Thank you for proposing CSS Relative Color Syntax for inclusion into Interop 2023.

We wanted to let you know that this proposal was not selected to be part of Interop this year. We had many strong proposals, and could not accept them all. However this should not be taken as a comment on the technology as a whole, and resubmitting a proposal for this feature as part of a future round of Interop would be welcome.

For an overview of our process, see the proposal selection summary. Thank you again for contributing to Interop 2023!

Posted on behalf of the Interop team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus-area-proposal Focus Area Proposal
Projects
No open projects
Status: Proposed
Development

No branches or pull requests

6 participants