Categories
CSS Web development

CSS repeating-linear-gradient() Function

CSS repeating-linear-gradient() Function

The CSS repeating-linear-gradient() function repeats linear gradients.

Syntax:

background-image: repeating-linear-gradient(angle | to side-or-corner, color-stop1, color-stop2...); 

angle – specifies an angle of direction for the gradient (default is 180deg).

side-or-corner – specifies the position of the starting-point of the gradient line. It consists of two keywords: the first one indicates the horizontal side, left or right, and the second one the vertical side, top or bottom. The order is not relevant and each of the keyword is optional.

color-stop1, color-stop2… – color stops are the colors you want to render smooth transitions among. This value consists of a color value, followed by an optional stop position (a percentage between 0% and 100% or a length along the gradient axis).

Example1:

<!DOCTYPE html>
<html>
<head>
<style>
#gradient-1 {
  height: 100px;
  position: relative;
  width: 200px;
  background-image: repeating-linear-gradient(yellow, orange 10%, green 20%);
}
</style>
</head>
<body>

<div id="gradient-1"></div>

</body>
</html>

Output:


Example2:

<!DOCTYPE html>
<html>
<head>
<style>
#gradient-2 {
  height: 100px;
  position: relative;
  width: 200px;
  background-image: repeating-linear-gradient(45deg,yellow,orange 7%,green 10%);
}
</style>
</head>
<body>

<div id="gradient-2"></div>

</body>
</html>

Output:


Enjoy coding!

Read also:

CSS Gradients

CSS linear-gradient() Function