Skip to content

Early draft explainer for contrast color lvl 6#1260

Open
diekus wants to merge 1 commit intoMicrosoftEdge:mainfrom
diekus:diekus-color-contrast-6
Open

Early draft explainer for contrast color lvl 6#1260
diekus wants to merge 1 commit intoMicrosoftEdge:mainfrom
diekus:diekus-color-contrast-6

Conversation

@diekus
Copy link
Member

@diekus diekus commented Feb 23, 2026

Early initial draft for contrast-color lvl 6

Early initial draft for contrast-color lvl 6
```
With these being the available parameters:

- `<color-role>`: `background` or `foreground`. Specifies the role of the base, known color. It is also necessary for some contrst algorithms.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `<color-role>`: `background` or `foreground`. Specifies the role of the base, known color. It is also necessary for some contrst algorithms.
- `<color-role>`: `background` or `foreground`. Specifies the role of the base, known color. It is also necessary for some contrast algorithms.


- `<color-role>`: `background` or `foreground`. Specifies the role of the base, known color. It is also necessary for some contrst algorithms.
- `<color>`: The base color that an author is looking to contrast against.
- `<contrast-algorithm>`: Which contrast calculation method to use (`auto`, `wcap`, `lstar`, `apca`, `weber` or `michelson`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As someone who is not familiar with these different algorithms, I think it would be helpful to include brief information about them and why this particular set was chosen for inclusion.

- `<color>`: The base color that an author is looking to contrast against.
- `<contrast-algorithm>`: Which contrast calculation method to use (`auto`, `wcap`, `lstar`, `apca`, `weber` or `michelson`).
- `<contrast-target>`: Follows the `prefers-contrast` media query syntax. (`auto` | `max` | `more` | `less` | `<custom-contrast-target>`). More, less and no-preference (auto) correlate with user preferences. Max is introduced to return black or white.
- `<custom-contrast-target>`: the desired contrast target ratio or a percentage. This ratio will fail or pass depending on the used algorithm to calculate contrast. Is is only used when the `<custom-contrast-target>` is set.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following this line. I'm reading that <custom-contrast-target> is used only when <custom-contrast-target> is set ... ?

The proposed syntax is as follows:

```css
contrast-color() = contrast-color(<color-role>? <color> / <contrast-target> <contrast-algorithm> <color>#{2,})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
contrast-color() = contrast-color(<color-role>? <color> / <contrast-target> <contrast-algorithm> <color>#{2,})
contrast-color() = contrast-color(<color-role>? <color> [ / <contrast-target>? <contrast-algorithm>? [ <color>#{2,} ]? ]? )

Two suggestions here:

  1. For back-compat with V1 contrast-color(), enclose the / and everything after it in [ ]? i.e. optional
  2. Make the trailing terms optional for cases where an author only wants to specify certain features, or not
    pick from a list but rather return a maximally contrasting color, make the candidate list optional

```css
body {
background: blue;
color: contrast-color(blue gold, orange, yellow);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
color: contrast-color(blue gold, orange, yellow);
color: contrast-color(blue / gold, orange, yellow);

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants