CSS radial-gradient() Function
Use the CSS radial-gradient() function to produce a radial gradient: colors that blend outward from a central point.
At least two color stops are required. These are the colors the gradient moves smoothly between.
Syntax
Defaults: ellipse for the shape, farthest-corner for the size, and center for the position.
background-image: radial-gradient(shape size at position, start-color, ..., last-color);
Radial Gradient - Evenly Spaced Color Stops (this is default)
Here the color stops are evenly spaced, which is what a radial gradient does by default:
Example
Output: complete HTML page
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Radial Gradient - Evenly Spaced</title>
<style>
#grad {
height: 200px;
width: 100%;
background-image: radial-gradient(red, yellow, green);
}
</style>
</head>
<body>
<h2>Radial Gradient - Evenly Spaced Color Stops</h2>
<div id="grad"></div>
</body>
</html>
Radial Gradient - Differently Spaced Color Stops
In this radial gradient, each color stop has a different spacing:
Example
Output: complete HTML page
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Radial Gradient - Differently Spaced</title>
<style>
#grad {
height: 200px;
width: 100%;
background-image: radial-gradient(red 5%, yellow 15%, green 60%);
}
</style>
</head>
<body>
<h2>Radial Gradient - Differently Spaced Color Stops</h2>
<div id="grad"></div>
</body>
</html>
Radial Gradient - Set Shape
Two values are available for the shape parameter, which controls the gradient's shape:
ellipse(the default)circle
Example
Here the radial gradient takes the shape of a circle:
Output: complete HTML page
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Radial Gradient - Circle Shape</title>
<style>
#grad {
height: 200px;
width: 100%;
background-image: radial-gradient(circle, red, yellow, green);
}
</style>
</head>
<body>
<h2>Radial Gradient - Circle Shape</h2>
<div id="grad"></div>
</body>
</html>
Radial Gradient - The size Parameter
How big the gradient's ending shape gets depends on the size parameter, which accepts these values:
closest-sidefarthest-sideclosest-cornerfarthest-corner(the default)
Example
Different size keywords produce different radial gradients:
Output: complete HTML page
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Radial Gradient - Size Parameter</title>
<style>
#grad1 {
height: 200px;
width: 100%;
background-image: radial-gradient(closest-side at 70% 60%, red, yellow, black);
}
#grad2 {
height: 200px;
width: 100%;
background-image: radial-gradient(farthest-side at 70% 60%, red, yellow, black);
}
</style>
</head>
<body>
<h2>Radial Gradient - Size Parameter</h2>
<p>closest-side:</p>
<div id="grad1"></div>
<p>farthest-side:</p>
<div id="grad2"></div>
</body>
</html>
CSS repeating-radial-gradient() Function
To make a radial gradient repeat, reach for the CSS repeating-radial-gradient() function:
Example
A radial gradient that repeats:
Output: complete HTML page
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Repeating Radial Gradient</title>
<style>
#grad {
height: 200px;
width: 100%;
background-image: repeating-radial-gradient(red, yellow 10%, green 15%);
}
</style>
</head>
<body>
<h2>Repeating Radial Gradient</h2>
<div id="grad"></div>
</body>
</html>