CSS repeating-linear-gradient() Function
Example
Repeating linear gradient:
#grad
{
background-image:
repeating-linear-gradient
(
red
,
yellow
10
%
,
green
20
%
)
;
}
Try it »
Definition and usage
The repeating-linear-gradient() function creates a repeating linear gradient background image.
The repeating-linear-gradient() function works like linear-gradient(), but after reaching the specified end point, the image repeats itself.
** Basic usage:**
background: repeating-linear-gradient(45deg, red, yellow 10%, green 20%);
This creates a linear gradient repeating at a 45-degree angle. It starts red, yellow at 10%, green at 20%, and then repeats.
Striped background:
background: repeating-linear-gradient(90deg, blue, blue 10px, white 10px, white 20px);
This creates a horizontal striped background, with each blue and white stripe 10 pixels wide.
Diagonal striped background
background: repeating-linear-gradient(135deg, black, black 15px, transparent 15px, transparent 30px);
This creates black and transparent diagonal stripes repeating at a 135-degree angle, each 15 pixels wide.
Create a zebra-stripe background
background: repeating-linear-gradient(90deg, #fff, #fff 10px, #000 10px, #000 20px);
Rainbow striped background
background: repeating-linear-gradient(45deg, red, orange 20px, yellow 40px, green 60px, blue 80px, indigo 100px, violet 120px);
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 | |||||
|---|---|---|---|---|---|
| repeating-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: repeating-linear-gradient(angle | to side-or-corner, color-stop1, color-stop2, ...);
| Value | Description |
|---|---|
| angle | Defines the angle direction of the gradient. From 0deg to 360deg, default is 180deg. |
| side-or-corner | Specifies the starting position of the linear gradient. It consists of two keywords: the first specifies the horizontal position (left or right), the second specifies the vertical position (top or bottom). The order is arbitrary, and each keyword is optional. |
| color-stop1, color-stop2,... | Specifies the color stops in the gradient; you can specify a color and a position, such as color 50%, meaning the color is at the 50% position of the gradient. |
More examples
Example
Different repeating linear gradients:
#grad1
{
background-image:
repeating-linear-gradient
(
45
deg
,
red
,
blue
7
%
,
green
10
%
)
;
}
#grad2
{
background-image:
repeating-linear-gradient
(
190
deg
,
red
,
blue
7
%
,
green
10
%
)
;
}
#grad3
{
background-image:
repeating-linear-gradient
(
90
deg
,
red
,
blue
7
%
,
green
10
%
)
;
}
Try it »
CSS Tutorial: CSS3 Gradients
CSS Functions