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

Add <(color|hue)-interpolation-method>; de-duplicate <hue> descriptions #26775

Merged
merged 65 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
64d5662
Create `<color-interpolation-method>`
yarusome May 15, 2023
7a42e21
Create `<hue-interpolation-method>`
yarusome May 15, 2023
c700aed
Upload diagrams
yarusome May 15, 2023
e4e6702
Fix image link
yarusome May 15, 2023
6778d8f
Merge branch 'main' into color-method
yarusome May 16, 2023
ad82ac4
Merge branch 'main' into color-method
yarusome May 17, 2023
bf4c6f3
Merge branch 'main' into color-method
queengooborg May 20, 2023
0ccc5d1
Tentative linting fix
yarusome May 20, 2023
43b180d
Linting
yarusome May 21, 2023
f2ce649
Linting
yarusome May 21, 2023
2dc7d79
Merge branch 'main' into color-method
yarusome May 21, 2023
3b3a3ea
Linting
yarusome May 21, 2023
3c8f7f5
Replace example for `<hue-interpolation-method>`
yarusome May 21, 2023
0233bcb
Wording
yarusome May 21, 2023
e1410af
Use larger height for example
yarusome May 21, 2023
9f1eb70
Merge branch 'mdn:main' into color-method
yarusome May 24, 2023
b8341d5
Update `<hue>`
yarusome May 24, 2023
b1fc497
Create color_wheel.svg
yarusome May 24, 2023
88916e8
Fix linting
yarusome May 24, 2023
ef5054e
Simplify wording
yarusome May 24, 2023
7a57c3d
Simplify wording
yarusome May 24, 2023
4dd7036
Simplify syntax of `color-mix()`
yarusome May 24, 2023
6cf7718
Relocate `<hue-interpolation-method>` example
yarusome May 24, 2023
c0476f4
Fix linting
yarusome May 24, 2023
19e46f3
De-duplicate `<hue>` from `hsl()`
yarusome May 24, 2023
3f4bfaa
Delete hue-wheel.png
yarusome May 24, 2023
90e406a
De-duplicate `<hue>` from `hwb()`
yarusome May 24, 2023
0f13110
De-duplicate `<hue>` from `lch()`
yarusome May 24, 2023
95f4f26
De-duplicate `<hue>` from `oklch()`
yarusome May 24, 2023
43a1f3f
Delete hue-wheel.png
yarusome May 24, 2023
243c3c7
Merge branch 'main' into color-method
yarusome May 24, 2023
7105583
Fine-tune `<hue-interpolation-method>`
yarusome May 24, 2023
a6b6ac2
Merge branch 'main' into color-method
yarusome May 25, 2023
7a68ec9
Merge branch 'mdn:main' into color-method
yarusome May 29, 2023
f76effa
Remove Level 5 content from `color()`
yarusome May 29, 2023
fd7c895
Uplift "Formal syntax" level
yarusome May 29, 2023
20cde55
Uplift "Formal syntax" level
yarusome May 29, 2023
bf2fb93
Update `<color>`
yarusome May 29, 2023
43ef616
Fix linting
yarusome May 29, 2023
881b938
Fix linting
yarusome May 29, 2023
e5c6739
Fine-tune `<color>` example
yarusome May 29, 2023
2287dae
Merge branch 'main' into color-method
bsmth Jun 1, 2023
a9d81b8
Apply suggestions from code review
yarusome Jun 2, 2023
5577d41
Add fallback for example on `<hue-interpolation>`
yarusome Jun 2, 2023
20ed98c
Eliminate custom variable
yarusome Jun 2, 2023
a1f2e94
Fix
yarusome Jun 2, 2023
bd5d0d8
Merge branch 'main' into color-method
yarusome Jun 2, 2023
5370c7c
Simplify
yarusome Jun 2, 2023
f160743
Tweak example
yarusome Jun 2, 2023
bcffa52
Remove "example hint"
yarusome Jun 2, 2023
04f320c
Update `<color>`
yarusome Jun 3, 2023
118c601
Merge branch 'main' into color-method
yarusome Jun 3, 2023
42483f0
Add back example for `color-mix()`
yarusome Jun 3, 2023
20da433
Fix link
yarusome Jun 3, 2023
7c76e3a
Update `hsl()`
yarusome Jun 3, 2023
74cf409
Update `hwb()`
yarusome Jun 3, 2023
88824d4
Update `lch()`
yarusome Jun 3, 2023
3f2f797
Update `oklch()`
yarusome Jun 3, 2023
1109772
Update `<color-interpolation-method>`
yarusome Jun 3, 2023
5493ca6
docs(CSS): Run prettier over color-interpolation-method page
bsmth Jun 5, 2023
eb37b62
Apply suggestion from code reivew
yarusome Jun 6, 2023
94f945b
Merge branch 'main' into color-method
bsmth Jun 8, 2023
270152d
Update files/en-us/web/css/hue-interpolation-method/index.md
yarusome Jun 12, 2023
6884c68
Merge branch 'mdn:main' into color-method
yarusome Jun 12, 2023
b87e2bd
Add `<named-color>` example for `<color>`
yarusome Jun 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions files/en-us/web/css/color-interpolation-method/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
---
title: <color-interpolation-method>
slug: Web/CSS/color-interpolation-method
page-type: css-type
browser-compat:
- css.types.color.color-mix
- css.types.image.gradient.conic-gradient.interpolation_color_space
- css.types.image.gradient.linear-gradient.interpolation_color_space
- css.types.image.gradient.radial-gradient.interpolation_color_space
- css.types.image.gradient.repeating-conic-gradient.interpolation_color_space
- css.types.image.gradient.repeating-linear-gradient.interpolation_color_space
- css.types.image.gradient.repeating-radial-gradient.interpolation_color_space
spec-urls: https://drafts.csswg.org/css-color/#interpolation-space
---

{{CSSRef}}

The **`<color-interpolation-method>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents the color space used for interpolation between {{CSSXref("&lt;color&gt;")}} values. It can be used to override the default interpolation color space for color-related functional notations such as {{CSSXref("color_value/color-mix", "color-mix()")}} and {{CSSXref("gradient/linear-gradient", "linear-gradient()")}}.

When interpolating `<color>` values, the interpolation color space defaults to Oklab.

## Syntax

The `<color-interpolation-method>` specifies whether interpolation should use a rectangular color space or a polar color space with an optional hue interpolation method:

```
in <rectangular-color-space>
// or
in <polar-color-space>[ <hue-interpolation method>]
```

### Values

- `<rectangular-color-space>`

- : One of the keywords `srgb`, `srgb-linear`, `lab`, `oklab`, `xyz`, `xyz-d50`, or `xyz-d65`.

- `<polar-color-space>`

- : One of the keywords `hsl`, `hwb`, `lch`, or `oklch`.

- {{CSSXref("&lt;hue-interpolation-method&gt;")}} {{optional_inline}}

- : The algorithm for hue interpolation. It defaults to `shorter hue`.

## Formal syntax

{{CSSSyntax}}

## Examples

### Comparing interpolation color spaces using gradients

The following example shows the effect of using different interpolation color spaces for {{CSSXref("gradient/linear-gradient", "linear-gradient()")}}.
yarusome marked this conversation as resolved.
Show resolved Hide resolved

#### HTML

```html
<div>sRGB:</div>
<div class="gradient srgb"></div>
<div>Oklab:</div>
<div class="gradient oklab"></div>
<div>Oklch (with <code>longer hue</code>):</div>
<div class="gradient oklch-longer"></div>
```

#### CSS

```css hidden
/* Fallback styles */
.srgb {
background-image: linear-gradient(
to right,
rgb(0% 0% 100%),
rgb(20% 0% 80%),
rgb(40% 0% 60%),
rgb(60% 0% 40%),
rgb(80% 0% 20%),
rgb(100% 0% 0%)
);
}
.oklab {
background-image: linear-gradient(
to right,
oklab(45.2% -0.032 -0.312),
oklab(48.7% 0.019 -0.224),
oklab(52.2% 0.07 -0.137),
oklab(55.8% 0.122 -0.049),
oklab(59.3% 0.173 0.038),
oklab(62.8% 0.225 0.126)
);
}
.oklch-longer {
background-image: linear-gradient(
to right,
oklch(45.2% 0.313 264),
oklch(46.8% 0.308 243),
oklch(48.4% 0.303 221),
oklch(50% 0.298 200),
oklch(51.6% 0.293 179),
oklch(53.2% 0.288 157),
oklch(54.8% 0.283 136),
oklch(56.4% 0.278 115),
oklch(58% 0.273 93),
oklch(59.6% 0.268 72),
oklch(61.2% 0.263 51),
oklch(62.8% 0.258 29)
);
}
```

```css
.gradient {
height: 50px;
width: 100%;
}
.srgb {
background-image: linear-gradient(in srgb to right, blue, red);
}
.oklab {
background-image: linear-gradient(in oklab to right, blue, red);
}
.oklch-longer {
background-image: linear-gradient(in oklch longer hue to right, blue, red);
}
```

#### Result

{{EmbedLiveSample("comparing_interpolation_color_spaces_using_gradients", "100%", 250)}}

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{CSSXref("&lt;color&gt;")}}, {{CSSXref("&lt;gradient&gt;")}}
- {{CSSXref("&lt;hue-interpolation-method&gt;")}}
99 changes: 36 additions & 63 deletions files/en-us/web/css/color_value/color-mix/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ browser-compat: css.types.color.color-mix

{{CSSRef}}

The **`color-mix()`** functional notation takes two {{cssxref("color_value","&lt;color>")}} values and returns the result of mixing them in a given colorspace by a given amount.
The **`color-mix()`** functional notation takes two {{cssxref("&lt;color&gt;")}} values and returns the result of mixing them in a given colorspace by a given amount.

## Syntax

Expand All @@ -20,29 +20,15 @@ color-mix(in hsl longer hue, hsl(120 100% 50%) 20%, white);

### Values

Functional notation: `color-mix(in colorspace[ hue-interpolation-method hue], color[ p1], color[ p2])`
Functional notation: `color-mix(method, color1[ p1], color2[ p2])`

- `in`
- `method`

- : A literal token as a component of the syntax.
- : A {{CSSXref("&lt;color-interpolation-method&gt;")}} specifying the interpolation color space.

- `colorspace`
- `color1`, `color2`

- : One of `srgb`, `srgb-linear`, `lab`, `oklab`, `xyz`, `xyz-d50`, `xyz-d65`, `hsl`, `hwb`, `lch`, or `oklch`, specifying the color space for interpolation.

- `hue-interpolation-method` {{optional_inline}}

- : One of `shorter`, `longer`, `increasing`, or `decreasing`, specifying how {{CSSXref("&lt;hue&gt;")}} values of the colors are interpolated.

> **Note:** This value is only valid if `colorspace` is one of `hsl`, `hwb`, `lch`, and `oklch`.

- `hue`

- : A literal token as a component of the syntax.

- `color`

- : Any valid {{CSSXref("&lt;color&gt;")}}.
- : {{CSSXref("&lt;color&gt;")}} values to mix.

- `p1`, `p2` {{optional_inline}}

Expand Down Expand Up @@ -127,77 +113,63 @@ li:nth-child(6) {

#### Result

{{EmbedLiveSample('Mixing two colors','100%', 150)}}
{{EmbedLiveSample("mixing_two_colors", "100%", 150)}}

### Using hue interpolation methods
### Using hue interpolation in color-mix()

Hue interpolation methods can be used to control how the {{cssxref("&lt;hue&gt;")}} is interpolated between two colors.
For `shorter` the result will be the shortest distance between the two angles (the default) and conversely, `longer` uses the larger value between the two angles in a circle.

For `increasing`, the result will be the angle between 0 and 360 degrees and for `decreasing` the result will be the angle between -360 and 0 degrees.

#### HTML
When using shorter hue interpolation, the resulting hue angle is halfway between the input angles when taking the shortest route around the color wheel.
The longer hue interpolation method results in a hue angle which is the midpoint when taking the longer route around the color wheel.
For more information, see {{cssxref("&lt;hue-interpolation-method&gt;")}}.

```html
<div id="shorter">shorter</div>
<div id="longer">longer</div>
<div id="increasing">increasing</div>
<div id="decreasing">decreasing</div>
<div class="color-one">color one</div>
<div class="color-two">color two</div>
<div class="shorter">mixed shorter</div>
<div class="longer">mixed longer</div>
```

#### CSS

```css hidden
body {
display: flex;
flex-wrap: wrap;
}
div {
width: 100px;
height: 100px;
margin: 10px;
border: 1px solid;
display: inline-block;
font: bold 150% monospace;
height: 100px;
margin: 10px 5%;
width: 30%;
}
```

```css
/* 20 degrees */
#shorter {
background-color: color-mix(
in hsl shorter hue,
hsl(10 100% 50%),
hsl(350 100% 50%)
);
.color-one {
background-color: hsl(10 100% 50%);
}

/* 340 degrees */
#longer {
background-color: color-mix(
in hsl longer hue,
hsl(10 100% 50%),
hsl(350 100% 50%)
);
.color-two {
background-color: hsl(60 100% 50%);
}

/* The resulting angle is between 0 and 360 degrees */
#increasing {
.shorter {
background-color: color-mix(
in hsl increasing hue,
in hsl shorter hue,
hsl(10 100% 50%),
hsl(350 100% 50%)
hsl(60 100% 50%)
);
}

/* The resulting angle is between -360 and 0 degrees */
#decreasing {
.longer {
background-color: color-mix(
in hsl decreasing hue,
in hsl longer hue,
hsl(10 100% 50%),
hsl(350 100% 50%)
hsl(60 100% 50%)
);
}
```

#### Result

{{EmbedLiveSample('Using hue interpolation methods','100%', 150)}}
yarusome marked this conversation as resolved.
Show resolved Hide resolved
{{EmbedLiveSample("using_hue_interpolation_in_color_mix", "100%", 250)}}

## Specifications

Expand All @@ -209,5 +181,6 @@ div {

## See also

- {{cssxref("color_value")}}
- {{CSSXref("&lt;color&gt;")}}
- {{CSSXref("&lt;color-interpolation-method&gt;")}}
- {{cssxref("&lt;hue&gt;")}}
12 changes: 5 additions & 7 deletions files/en-us/web/css/color_value/color/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ The **`color()`** functional notation allows a color to be specified in a partic

Support for a particular colorspace can be detected with the [`color-gamut`](/en-US/docs/Web/CSS/@media/color-gamut) CSS media feature.

The [`@color-profile`](/en-US/docs/Web/CSS/@color-profile) [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) can be used to define and name a color profile to be used in the `color()` function to specify a color.
bsmth marked this conversation as resolved.
Show resolved Hide resolved

## Syntax

```css
Expand Down Expand Up @@ -93,11 +91,11 @@ div {

#### Result

{{EmbedLiveSample('Using_predefined_colorspaces_with_color')}}
{{EmbedLiveSample("using_predefined_colorspaces_with_color")}}

### Using xyz colorspaces with color()
### Using the xyz colorspace with color()

The following example shows how to use `xyz` colorspaces to specify a color.
The following example shows how to use the `xyz` colorspace to specify a color.

#### HTML

Expand Down Expand Up @@ -136,7 +134,7 @@ div {

#### Result

{{EmbedLiveSample('Using_xyz_colorspaces_with_color')}}
{{EmbedLiveSample("using_the_xyz_colorspace_with_color")}}

### Using color-gamut media queries with color()

Expand Down Expand Up @@ -185,7 +183,7 @@ div {

#### Result

{{EmbedLiveSample('Using_color-gamut_media_queries_with_color')}}
{{EmbedLiveSample("using_color-gamut_media_queries_with_color")}}

## Specifications

Expand Down
Binary file removed files/en-us/web/css/color_value/hsl/hue-wheel.png
Binary file not shown.
Loading