-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
193 lines (141 loc) · 4.85 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
---
title: <gradient>
slug: Web/CSS/gradient
page-type: css-type
browser-compat: css.types.image.gradient
---
{{CSSRef}}
The **`<gradient>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) is a special type of {{cssxref("<image>")}} that consists of a progressive transition between two or more colors.
{{EmbedInteractiveExample("pages/css/type-gradient.html")}}
A CSS gradient has [no intrinsic dimensions](/en-US/docs/Web/CSS/image#description); i.e., it has no natural or preferred size, nor a preferred ratio. Its concrete size will match the size of the element to which it applies.
## Syntax
The `<gradient>` data type is defined with one of the function types listed below.
### Linear gradient
Linear gradients transition colors progressively along an imaginary line. They are generated with the {{cssxref("gradient/linear-gradient", "linear-gradient()")}} function.
### Radial gradient
Radial gradients transition colors progressively from a center point (origin). They are generated with the {{cssxref("gradient/radial-gradient", "radial-gradient()")}} function.
### Conic gradient
Conic gradients transition colors progressively around a circle. They are generated with the {{cssxref("gradient/conic-gradient", "conic-gradient()")}} function.
### Repeating gradient
Repeating gradients duplicate a gradient as much as necessary to fill a given area. They are generated with the {{cssxref("gradient/repeating-linear-gradient", "repeating-linear-gradient()")}}, {{cssxref("gradient/repeating-radial-gradient", "repeating-radial-gradient()")}}, and {{cssxref("gradient/repeating-conic-gradient", "repeating-conic-gradient()")}} functions.
## Interpolation
As with any interpolation involving colors, gradients are calculated in the alpha-premultiplied color space. This prevents unexpected shades of gray from appearing when both the color and the opacity are changing. (Be aware that older browsers may not use this behavior when using the [transparent keyword](/en-US/docs/Web/CSS/named-color#transparent).)
## Formal syntax
{{csssyntax}}
## Examples
### Linear gradient example
A simple linear gradient.
```html hidden
<div class="linear-gradient">Linear gradient</div>
```
```css hidden
div {
width: 240px;
height: 80px;
}
```
```css
.linear-gradient {
background: linear-gradient(
to right,
red,
orange,
yellow,
green,
blue,
indigo,
violet
);
}
```
{{EmbedLiveSample('Linear_gradient_example', 240, 120)}}
### Radial gradient example
A simple radial gradient.
```html hidden
<div class="radial-gradient">Radial gradient</div>
```
```css hidden
div {
width: 240px;
height: 80px;
}
```
```css
.radial-gradient {
background: radial-gradient(red, yellow, rgb(30 144 255));
}
```
{{EmbedLiveSample('Radial_gradient_example', 240, 120)}}
### Conic gradient example
A simple conic gradient example. Note that this isn't supported widely across browser as of yet.
```html hidden
<div class="conic-gradient">Conic gradient</div>
```
```css hidden
div {
width: 200px;
height: 200px;
}
```
```css
.conic-gradient {
background: conic-gradient(pink, coral, lime);
}
```
{{EmbedLiveSample('Conic_gradient_example', 240, 240)}}
### Repeating gradient examples
Simple repeating linear and radial gradient examples.
```html hidden
<div class="linear-repeat"></div>
<span>Repeating linear gradient</span>
<hr />
<div class="radial-repeat"></div>
<span>Repeating radial gradient</span>
<hr />
<div class="conic-repeat"></div>
<span>Repeating conic gradient</span>
```
```css hidden
div {
display: inline-block;
width: 240px;
height: 80px;
}
span {
font-weight: bold;
vertical-align: top;
}
```
```css
.linear-repeat {
background: repeating-linear-gradient(
to top left,
pink,
pink 5px,
white 5px,
white 10px
);
}
.radial-repeat {
background: repeating-radial-gradient(
lime,
lime 15px,
white 15px,
white 30px
);
}
.conic-repeat {
background: repeating-conic-gradient(lime, pink 30deg);
}
```
{{EmbedLiveSample('Repeating_gradient_examples', 240, 300)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Using CSS gradients](/en-US/docs/Web/CSS/CSS_images/Using_CSS_gradients)
- Gradient functions: {{cssxref("gradient/linear-gradient", "linear-gradient()")}}, {{cssxref("gradient/repeating-linear-gradient", "repeating-linear-gradient()")}}, {{cssxref("gradient/radial-gradient", "radial-gradient()")}}, {{cssxref("gradient/repeating-radial-gradient", "repeating-radial-gradient()")}}, {{cssxref("gradient/conic-gradient", "conic-gradient()")}}, {{cssxref("gradient/repeating-conic-gradient", "repeating-conic-gradient()")}}
- [CSS Basic Data Types](/en-US/docs/Web/CSS/CSS_Types)
- [CSS Units and Values](/en-US/docs/Web/CSS/CSS_Values_and_Units)
- [Introduction to CSS: Values and Units](/en-US/docs/Learn/CSS/Building_blocks/Values_and_units)