Early draft explainer for contrast color lvl 6#1260
Open
diekus wants to merge 1 commit intoMicrosoftEdge:mainfrom
Open
Early draft explainer for contrast color lvl 6#1260diekus wants to merge 1 commit intoMicrosoftEdge:mainfrom
diekus wants to merge 1 commit intoMicrosoftEdge:mainfrom
Conversation
Early initial draft for contrast-color lvl 6
kbabbitt
reviewed
Mar 12, 2026
| ``` | ||
| 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. |
Member
There was a problem hiding this comment.
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`). |
Member
There was a problem hiding this comment.
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. |
Member
There was a problem hiding this comment.
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,}) |
Member
There was a problem hiding this comment.
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:
- For back-compat with V1
contrast-color(), enclose the/and everything after it in[ ]?i.e. optional - 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); |
Member
There was a problem hiding this comment.
Suggested change
| color: contrast-color(blue gold, orange, yellow); | |
| color: contrast-color(blue / gold, orange, yellow); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Early initial draft for contrast-color lvl 6