CSS radial-gradient() Function
Last Updated :
04 Oct, 2024
The radial-gradient() function in CSS is used to create attractive background effects. It creates a gradient that starts from a central point and spreads outward. By default, the gradient begins in the center of the element and smoothly fades to the final color at the edges.
You can customize the shape, size, position, and colors of the gradient to design more complex and interesting backgrounds. In this article, we’ll explain how the radial-gradient() function works, and its syntax, and give some examples for clarity.
Syntax
background-image: radial-gradient( shape size at position, start-color, ..., last-color );
Parameters value
This function accepts many parameters which are listed below:
- shape: The shape of the gradient, either circle or ellipse (default is ellipse).
- size: The size of the gradient. Options include:
- farthest-corner (default)
- closest-side
- closest-corner
- farthest-side
- position: The starting point of the gradient, with the default being the center.
- colors: Defines the starting color, ending color, and any color stops in between.
The below example illustrates the radial-gradient() function in CSS:
Examples of radial-gradient() Function
Example 1: Basic Radial Gradient
This example demonstrates the use of a radial gradient background with three colors transitioning from dark green (#090) to white (#fff) to a darker green (#2a4f32). The text inside is centered and styled with different font sizes and weights for emphasis.
html
<!DOCTYPE html>
<html>
<head>
<title>CSS Gradients</title>
<style>
#main {
height: 250px;
width: 600px;
background-color: white;
background-image:
radial-gradient(#090, #fff, #2a4f32);
}
.gfg {
text-align: center;
font-size: 40px;
font-weight: bold;
padding-top: 80px;
}
.geeks {
font-size: 17px;
text-align: center;
}
</style>
</head>
<body>
<div id="main">
<div class="gfg">
GeeksforGeeks
</div>
<div class="geeks">
A computer science portal for geeks
</div>
</div>
</body>
</html>
Output:

Example 2: Customised Radial Gradient
This example uses a circular radial gradient as the background, transitioning from green to white and then blue. The text is centered vertically and horizontally, with a bold heading and smaller subtitle, creating a visually appealing layout with a gradient effect.
html
<!DOCTYPE html>
<html>
<head>
<title>CSS Gradients</title>
<style>
#main {
height: 400px;
width: 600px;
background-color: white;
background-image:
radial-gradient(circle, green, white, blue);
}
.gfg {
text-align: center;
font-size: 40px;
font-weight: bold;
padding-top: 155px;
}
.geeks {
font-size: 17px;
text-align: center;
}
</style>
</head>
<body>
<div id="main">
<div class="gfg">
GeeksforGeeks
</div>
<div class="geeks">
A computer science portal for geeks
</div>
</div>
</body>
</html>
Output:

The radial-gradient() function in CSS offers a versatile and powerful way to enhance the visual appeal of web pages. By mastering its syntax and parameters, developers can create dynamic and responsive background effects that improve user experience. Whether you are designing for desktop or mobile, radial-gradient() provides the flexibility needed to achieve stunning visual results. As it is supported by all major browsers, you can confidently incorporate radial gradients into your designs for a consistent and engaging look across different platforms.
Supported Browser
CSS radial-gradient() Function – FAQs
What does the radial-gradient() function do in CSS?
The radial-gradient() function creates a gradient that radiates from a central point, transitioning between multiple colors outward, often used for backgrounds and shapes.
How do you define a radial gradient in CSS?
Define a radial gradient using background: radial-gradient(shape size at position, color-stop1, color-stop2, …);.
Can radial-gradient() be used with shapes other than circles?
Yes, radial gradients can be circular or elliptical, defined by specifying the shape and size keywords like circle or ellipse.
What are common uses for radial-gradient() in CSS?
Common uses include creating buttons, backgrounds, and visual effects that require a focal point or radiating design.
Can I animate radial-gradient() in CSS?
Yes, radial gradients can be animated using CSS animations or transitions, allowing for dynamic changes in colors or shapes.
Similar Reads
CSS attr() Function
The attr() function is an inbuilt function in CSS that returns the value of an attribute of the selected elements. Syntax: attr( attr_name )Parameter: This function accepts a single parameter attr_name which is used to hold the name of the attribute in an HTML element. It is a mandatory parameter. R
2 min read
CSS blur() Function
The CSS blur() function applies a Gaussian blur effect to an element, making it appear out of focus. It is used with the filter property and accepts a length value defining the blur radius. CSS blur() function is part of the CSS filter property, which allows you to apply graphical effects like blurr
3 min read
CSS brightness() Function
The brightness() function is an inbuilt function which is used to apply a filter to set the brightness of the image. This function uses the linear multiplier to the image to increase or decrease brightness. Syntax: brightness( amount ) Parameters: This function accepts single parameter amount which
1 min read
CSS calc() Function
The calc() function is an inbuilt CSS function used to perform calculations to determine CSS property values dynamically. This function allows combining different units, such as percentages and pixels, using basic arithmetic operations like addition, subtraction, multiplication, and division. This a
4 min read
CSS circle() function
The circle() function is an inbuilt function in CSS that is used to create floating text around the circular shape picture or anything else. Syntax: circle(100px at 10px 150px); or circle( percentage ); Parameters: This function accepts a single parameter length or percentage which is used to hold t
3 min read
CSS conic-gradient() Function
The conic-gradient() function is an inbuilt function in CSS that is used to set a conic gradient as the background image. The conic gradient angle starts from 0 degrees - 360 degrees. Conic are circular and use the center of the element as the source point for color stop. Conic Gradients include pie
4 min read
CSS contrast() Function
The contrast() function is an inbuilt function which is used to apply a filter to set the contrast of the image. This function adjusts the contrast of the image. Syntax: contrast( amount ) Parameters: This function accepts single parameter amount which holds the amount of contrast. The value of cont
1 min read
CSS cubic-bezier() Function
The cubic-bezier() function is an inbuilt function in CSS that is used to define a Cubic Bezier curve. A Bezier curve is a mathematically defined curve used in two-dimensional graphic applications like adobe illustrator, Inkscape, etc. The curve is defined by four points: the initial position and th
1 min read
CSS drop-shadow() Function
The CSS drop-shadow() function adds a shadow effect to elements, like images, using horizontal and vertical offsets, blur radius, spread radius, and color parameters. It enhances visual depth and prominence in web design. Syntax: filter: drop-shadow(offset-x offset-y blur-radius spread-radius color)
3 min read
CSS ellipse() Function
The ellipse() function is an inbuilt function in CSS used to create floating text around the ellipse shape picture or anything else. Syntax: circle(100px 10 px at 10px 150px);or ellipse( percentage percentage );Parameter: This function accepts a single parameter length or percentage which is used to
3 min read