-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
105 lines (78 loc) · 3.15 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
title: saturate()
slug: Web/CSS/filter-function/saturate
page-type: css-function
browser-compat: css.types.filter-function.saturate
---
{{CSSRef}}
The **`saturate()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) super-saturates or desaturates the input image. Its result is a {{cssxref("<filter-function>")}}.
> **Note:** `saturate()` is specified as a matrix operation on the RGB color. It does not actually convert the color to the HSL model, which is a non-linear operation. Therefore, it may not preserve the hue or lightness of the original color.
{{EmbedInteractiveExample("pages/css/function-saturate.html")}}
## Syntax
```css
saturate(amount)
```
### Parameters
- `amount`
- : The amount of the conversion, specified as a {{cssxref("<number>")}} or a {{cssxref("<percentage>")}}. A value under `100%` desaturates the image, while a value over `100%` super-saturates it. A value of `0%` is completely unsaturated, while a value of `100%` leaves the input unchanged. The initial value for {{Glossary("interpolation")}} is `1`.
## Examples
### Examples of correct values for saturate()
```css
saturate(0) /* Completely unsaturated */
saturate(.4) /* 40% saturated */
saturate(100%) /* No effect */
saturate(200%) /* Double saturation */
```
### saturate() does not preserve hue or lightness
The diagram below compares two color gradients with `hsl(0, 50%, 50%)` as the mid-point: the first is generated using `saturate()`, and the second uses actual HSL color values. Note how the `saturate()` gradient shows differences in hue and lightness towards the two ends.
```html
<div>
<p>Using <code>saturate()</code></p>
<div id="saturate"></div>
</div>
<div>
<p>Using <code>hsl()</code></p>
<div id="hsl"></div>
</div>
```
```css hidden
#saturate,
#hsl {
display: flex;
margin: 1em 0;
}
#saturate div,
#hsl div {
width: 2px;
height: 100px;
}
```
```js
const saturate = document.getElementById("saturate");
const hsl = document.getElementById("hsl");
for (let i = 0; i <= 200; i++) {
const div1 = document.createElement("div");
div1.style.backgroundColor = `hsl(0, ${i / 2}%, 50%)`;
hsl.appendChild(div1);
const div2 = document.createElement("div");
div2.style.backgroundColor = "hsl(0, 50%, 50%)";
div2.style.filter = `saturate(${i}%)`;
saturate.appendChild(div2);
}
```
{{EmbedLiveSample('saturate_does_not_preserve_hue_or_lightness','100%','350')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
The other {{cssxref("<filter-function>")}} functions available to be used in values of the {{cssxref("filter")}} and {{cssxref("backdrop-filter")}} properties include:
- {{cssxref("filter-function/blur", "blur()")}}
- {{cssxref("filter-function/brightness", "brightness()")}}
- {{cssxref("filter-function/contrast", "contrast()")}}
- {{cssxref("filter-function/drop-shadow", "drop-shadow()")}}
- {{cssxref("filter-function/grayscale", "grayscale()")}}
- {{cssxref("filter-function/hue-rotate", "hue-rotate()")}}
- {{cssxref("filter-function/invert", "invert()")}}
- {{cssxref("filter-function/opacity", "opacity()")}}
- {{cssxref("filter-function/sepia", "sepia()")}}