What is the CSS repeating-radial-gradient() function?
The repeating-radial-gradient() function creates gradients in a repeated fashion, as shown in the image below.
- It is an in-built CSS function.
- It can be only used where images are used because this function returns a
.gradientdata typeThis is a special kind of image
Syntax
background-image: repeating-radial-gradient(shape extent-keyword at position,
color stops...);
or
background: repeating-radial-gradient(shape extent-keyword at position,
color stops...);
Parameters
repeating-radial-gradient function accepts following parameters:
-
Shape: The default shape is an ellipse, which can be replaced with only a circle. -
Extent-Keyword: It is used to specify the size of the ending shape .farthest-corner(default),closest-side,closest-corner,farthest-side. -
Position: It specifies the position where the gradient originates. The default iscenter.
repeating-radial-gradient(circle at center, red 0, blue, green 30px);
We can provide the position in percentages too.
repeating-radial-gradient(farthest-corner at 20% 20%, red 0, green, red 20%);
- Color stops: These are used to specify the colors in the gradient. They also follow an optional stop position.
Example 1
In the following code snippet:
-
We created a
divelement which has agradientto applyrepeating-radial-gradient. -
We passed the
repeating-radial-gradientfunction to a background CSS property togradientdivinstyletag.
repeating-radial-gradient(circle at center, red 0, blue, green 30px);
-
Here we passed the parameters to make the shape
circle, the positioncenterand color stops asred,blue,green. -
The gradient starts with
red, changes toblue, and ends withgreen.
Example 2
In this example, we will try to animate the gradient. We will take the advantage of optional color-stop positions.
-
In the following gradient, we used two shades of color stops,
pinkandwhite. -
We provided color-stops positions to white and pink as
0and100. -
We will change the color stop position of pink from
100to0and animate it using CSS animations.