CSS linear-gradient() Function
Example
The following example demonstrates a linear gradient starting from the top, beginning with red, turning to yellow, then to blue:
#grad
{
background-image:
linear-gradient
(
red
,
yellow
,
blue
)
;
}
Try it »
Definition and usage
The linear-gradient() function creates an image representing a linear gradient of two or more colors.
To create a linear gradient, you need to specify two colors. You can also create gradients in different directions (specified as an angle); if no direction is specified, the gradient defaults from top to bottom.
/*
From top to bottom, blue gradient to red
*/
linear-gradient
(
blue
,
red
);
/*
Gradient axis at 45 degrees, blue gradient to red
*/
linear-gradient
(45
deg
,
blue
,
red
);
/*
From bottom-right to top-left, blue gradient to red
*/
linear-gradient
(
to
left
top
,
blue
,
red
);
/*
From bottom to top, starting with blue, green begins at the 40% height position, ending with red
*/
linear-gradient
(0
deg
,
blue
,
green
40%,
red
);
CSS online gradient generator:https://www.jyshare.com/front-end/9921/.
Linear gradient example

Supported version: CSS3
Browser support
The numbers in the table indicate the first browser version that supports the function.
The number prefixed by "webkit", "moz", or "o" indicates the first version that supports the function.
| function | |||||
|---|---|---|---|---|---|
| linear-gradient() | 26.0 | ||||
| 10.0 -webkit- | 10.0 | 16.0 | |||
| 3.6 -moz- | 6.1 | ||||
| 5.1 -webkit- | 12.1 | ||||
| 11.1 -o- |
CSS Syntax
background-image: linear-gradient(direction, color-stop1, color-stop2, ...);
| Value | Description |
|---|---|
| direction | Specifies the direction (or angle) of the gradient with an angle value. |
| color-stop1, color-stop2,... | Used to specify the start and end colors of the gradient. |
More examples
Example
The following example demonstrates a linear gradient starting from the left, beginning with red, turning to yellow:
#grad
{
background-image:
linear-gradient
(
to
right
,
red
,
yellow
)
;
}
Try it »
Example
The following example demonstrates a linear gradient from top-left to bottom-right:
#grad
{
background-image:
linear-gradient
(
to
bottom
right
,
red
,
yellow
)
;
}
Try it »
Example
The following example demonstrates a linear gradient with a specified angle:
#grad
{
background-image:
linear-gradient
(
180
deg
,
red
,
yellow
)
;
}
Try it »
Example
The following example demonstrates multiple color stops:
#grad
{
background-image:
linear-gradient
(
to
right
,
red
,
orange
,
yellow
,
green
,
blue
,
indigo
,
violet
)
;
}
Try it »
Example
The following example uses transparency:
#grad
{
background-image:
linear-gradient
(
to
right
,
rgba
(
255
,
0
,
0
,
0
),
rgba
(
255
,
0
,
0
,
1
))
;
}
Try it »
CSS Tutorial: CSS3 Gradients
CSS Functions