How to Make a Radial Gradient Background in CSS: A Complete Guide
A well-designed background can transform an ordinary website into a visually appealing experience. While solid colors are simple and effective, gradients add depth, contrast, and visual interest without requiring image files or complicated design tools. One particularly useful option is a radial gradient, which creates a smooth transition between colors that spreads outward from a central point.
If you want to learn how to make a radial gradient background in CSS, you can achieve it with the built-in radial-gradient() function. This CSS feature allows you to create everything from subtle background highlights and glowing effects to colorful hero sections and modern landing page designs.
In this guide, you'll learn how radial gradients work, how to create them with practical CSS examples, how to control their shape and position, and how to combine multiple gradients for more advanced effects. You'll also discover common mistakes to avoid and useful tips for creating attractive, responsive backgrounds.
Whether you're a beginner learning CSS or an experienced developer refining a website's design, these examples will help you use radial gradients confidently.
What Is a Radial Gradient in CSS?
A radial gradient is a CSS background effect in which colors transition outward from a central point. Unlike a linear gradient, which follows a straight line, a radial gradient expands in a circular or elliptical pattern.
For example, you can create a background that starts with a bright blue color in the center and gradually transitions to dark navy around the edges. This effect is useful for drawing attention to a heading, highlighting a product, or adding depth to a website section.
CSS provides the radial-gradient() function to create this effect directly in the browser.
Here are some common uses for radial gradients:
- Creating colorful website hero backgrounds.
- Adding a soft glow behind headings or buttons.
- Designing modern landing pages.
- Highlighting product images or illustrations.
- Creating decorative backgrounds for cards.
- Building abstract backgrounds without external images.
One major advantage is that CSS generates the gradient dynamically. You don't need to download an image, and you can easily change its colors, size, and position by editing a few CSS properties.
Basic Syntax of the CSS Radial Gradient Function
To create a radial gradient background, use the radial-gradient() function inside the CSS background or background-image property.
The basic syntax is:
background: radial-gradient(
shape size at position,
color-stop1,
color-stop2,
...
);
Each part controls a different aspect of the gradient.
- Shape: Determines whether the gradient is circular or elliptical.
- Size: Controls how far the gradient extends from its center.
- Position: Specifies where the gradient originates.
- Color stops: Define the colors and where transitions between them occur.
The shape, size, and position are optional. If you leave them out, CSS uses its default radial gradient settings.
For example:
body {
margin: 0;
min-height: 100vh;
background: radial-gradient(
#74ebd5,
#3a7bd5
);
}
This creates a smooth gradient that begins with a light turquoise color near the center and transitions to blue toward the outside.
You can replace these colors with your own hex codes, RGB values, HSL values, or supported CSS color names.
How to Make a Simple Radial Gradient Background in CSS
The easiest way to create a radial gradient is to specify two or more colors.
Step 1: Create an HTML element
Start with a basic HTML document.
CSS Radial Gradient
Welcome to My Website
Step 2: Apply the radial gradient
Add the following CSS to the document's section or your external stylesheet.
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
background: radial-gradient(
circle,
#ff9966,
#ff5e62
);
color: white;
font-family: Arial, sans-serif;
}
h1 {
font-size: clamp(2rem, 5vw, 4rem);
text-align: center;
}
The circle keyword creates a circular gradient. The first color, #ff9966, appears at the center, while #ff5e62 appears toward the outer edge.
The min-height: 100vh declaration allows the body to fill at least the height of the viewport. The grid properties center the heading horizontally and vertically.
You now have a complete radial gradient background using only CSS.
Step 3: Customize the colors
Experiment with different color combinations to match your website's visual identity.
For example, you could try:
background: radial-gradient(
circle,
#a8edea,
#fed6e3
);
This creates a soft pastel effect suitable for personal websites, portfolios, and lifestyle brands.
For a darker design, try:
background: radial-gradient(
circle,
#434343,
#000000
);
The important principle is to select colors that complement your website's content and maintain sufficient contrast for text and interface elements.
Understanding Radial Gradient Shapes
CSS supports two main radial gradient shapes: circle and ellipse.
1. Circular radial gradient
A circular gradient expands from the center in a circular pattern. Its radius is the same in every direction.
.gradient-circle {
min-height: 400px;
background: radial-gradient(
circle,
#f6d365,
#fda085
);
}
Use a circular gradient when you want a concentrated glow, a spotlight effect, or a decorative color pattern.
It works especially well behind centered content, illustrations, and product images.
2. Elliptical radial gradient
An elliptical gradient expands in an oval shape. Its horizontal and vertical dimensions can differ.
.gradient-ellipse {
min-height: 400px;
background: radial-gradient(
ellipse,
#667eea,
#764ba2
);
}
An ellipse is useful for wide website sections because its shape can adapt naturally to the dimensions of the element.
Which shape should you choose?
| Feature | Circle | Ellipse |
|---|---|---|
| Shape | Perfect circle | Oval |
| Visual effect | Focused, balanced glow | Wide, flowing transition |
| Best use | Icons, cards, spotlight effects | Hero sections, large backgrounds |
| Size behavior | Equal radius in all directions | Different horizontal and vertical radii |
If you don't specify a shape, CSS uses an elliptical gradient by default.
How to Control Radial Gradient Size in CSS
The size of a radial gradient determines how far its color transition extends. CSS provides several keywords to control its ending shape.
Closest-side
The closest-side keyword makes the gradient end at the nearest side of the element from its center.
.gradient-small {
min-height: 400px;
background: radial-gradient(
circle closest-side,
#00c6ff,
#0072ff
);
}
This can produce a compact gradient that leaves more room for the final color around the edges.
Farthest-side
The farthest-side keyword extends the gradient to the farthest side of the element.
.gradient-wide {
min-height: 400px;
background: radial-gradient(
circle farthest-side,
#ff758c,
#ff7eb3
);
}
This is useful when you want the gradient to cover more of the background.
Closest-corner
The closest-corner keyword sizes the gradient to reach the nearest corner of the element.
.gradient-corner {
min-height: 400px;
background: radial-gradient(
circle closest-corner,
#43e97b,
#38f9d7
);
}
Farthest-corner
The farthest-corner keyword extends the gradient to the farthest corner. It is the default sizing behavior for a circular or elliptical radial gradient when no other size is specified.
.gradient-full {
min-height: 400px;
background: radial-gradient(
circle farthest-corner,
#667eea,
#764ba2
);
}
You can also provide explicit dimensions, such as 150px 100px, after the shape to define the horizontal and vertical radii of an elliptical gradient.
background: radial-gradient(
ellipse 150px 100px,
#ffffff,
#2563eb
);
Experiment with these settings to control whether the background appears concentrated or spreads across the entire element.
How to Change the Position of a Radial Gradient
By default, a radial gradient begins at the center of its background area. However, you can move the starting point using the at keyword.
Position the gradient at the top
.hero {
min-height: 500px;
background: radial-gradient(
circle at top,
#fdfbfb,
#ebedee
);
}
This places the gradient's center at the top of the element.
Position the gradient in a corner
.hero {
min-height: 500px;
background: radial-gradient(
circle at top left,
#ffecd2,
#fcb69f
);
}
This is helpful for creating a decorative glow behind a heading or an illustration positioned in the opposite corner.
Use custom percentage positions
You can specify an exact position with percentages.
.hero {
min-height: 500px;
background: radial-gradient(
circle at 30% 20%,
#89f7fe,
#66a6ff
);
}
In this example, the gradient's center is positioned 30% across the element and 20% down from its top-left corner.
You can also use pixel values:
background: radial-gradient(
circle at 200px 100px,
#ff9a9e,
#fad0c4
);
Percentage positioning is generally more flexible for responsive layouts because it adapts to the element's dimensions.
How to Create a Radial Gradient With Three or More Colors
A radial gradient does not have to contain only two colors. You can include multiple color stops to create richer transitions.
body {
min-height: 100vh;
margin: 0;
background: radial-gradient(
circle,
#ffdd00,
#ff6a00,
#ee0979,
#6a11cb
);
}
This gradient transitions from yellow in the center through orange and pink to purple near the outside.
You can also specify the position of each color stop to control how quickly the colors change.
.hero {
min-height: 500px;
background: radial-gradient(
circle,
#ffffff 0%,
#dbeafe 20%,
#60a5fa 50%,
#1e3a8a 100%
);
}
Here is how the stops work:
0%: White begins at the center.20%: The gradient reaches a pale blue.50%: The background transitions to a stronger blue.100%: The gradient reaches dark blue at its ending radius.
Color stops give you greater control over the final result. For a soft, modern design, use gradual transitions. For a more dramatic effect, place stops closer together.
How to Create a Radial Gradient Background for a Website Hero Section
Hero sections are ideal places to use radial gradients because they often need a strong visual focal point without distracting from the main message.
The following example creates a dark background with a blue glow behind the heading.
.hero {
min-height: 80vh;
display: grid;
place-items: center;
padding: 2rem;
text-align: center;
background: radial-gradient(
ellipse at 50% 35%,
#1e40af 0%,
#111827 55%,
#030712 100%
);
color: #ffffff;
}
.hero-content {
max-width: 700px;
}
.hero h1 {
margin-bottom: 1rem;
font-size: clamp(2.5rem, 6vw, 5rem);
}
.hero p {
color: #d1d5db;
font-size: 1.125rem;
line-height: 1.7;
}
.hero-button {
display: inline-block;
margin-top: 1rem;
padding: 0.85rem 1.5rem;
border-radius: 8px;
background: #ffffff;
color: #111827;
text-decoration: none;
font-weight: 700;
}
The gradient creates a blue focal point near the upper center while the background darkens toward the edges.
The clamp() function makes the heading responsive, while the max-width declaration keeps the text readable on larger screens.
For the best results, keep the brightest part of the gradient near the content you want visitors to notice. Make sure text and buttons remain readable across the entire section.
How to Create a Soft Glow Effect With Radial Gradients
A soft glow can add depth to a card, product showcase, or landing page. You can create one by placing a transparent color near the center and allowing it to fade into transparency.
.glow-background {
min-height: 400px;
background: radial-gradient(
circle at center,
rgba(59, 130, 246, 0.35) 0%,
rgba(59, 130, 246, 0.08) 40%,
transparent 70%
);
background-color: #0f172a;
}
The blue glow gradually fades into the dark background because the final color stop is transparent.
This approach is particularly useful for:
- Dark-mode dashboards.
- SaaS landing pages.
- Technology and AI websites.
- Product feature sections.
- Decorative backgrounds behind illustrations.
If the glow looks too strong, reduce the alpha values in the rgba() colors. If it looks too small, adjust the gradient size or change the color-stop positions.
Remember that a transparent gradient reveals whatever background is underneath it. The background-color declaration provides the dark base in this example.
How to Combine Multiple Radial Gradients
One of the most powerful CSS background techniques is combining multiple gradients in the same background declaration.
Each gradient is separated by a comma.
body {
min-height: 100vh;
margin: 0;
background:
radial-gradient(
circle at 15% 20%,
rgba(59, 130, 246, 0.45),
transparent 35%
),
radial-gradient(
circle at 85% 30%,
rgba(168, 85, 247, 0.4),
transparent 35%
),
radial-gradient(
circle at 50% 85%,
rgba(236, 72, 153, 0.3),
transparent 40%
),
#0b1020;
}
This creates three colorful glows over a dark base color.
The first gradient adds blue near the upper-left area. The second creates a purple glow near the upper-right area, while the third adds a subtle pink highlight toward the bottom.
Important: CSS paints the first background layer on top of the layers that follow it. In this example, the transparent areas allow the lower layers to remain visible.
To create a more balanced composition:
- Use two or three gradients before adding more.
- Keep the glow colors related to your brand palette.
- Use transparency to prevent overlapping colors from becoming too intense.
- Test the background on both small and large screens.
- Ensure the text remains readable over every part of the background.
Multiple radial gradients can create sophisticated backgrounds without external images, but adding too many layers may increase rendering work on some devices.
Radial Gradient vs. Linear Gradient in CSS
Both radial and linear gradients are useful for website backgrounds, but they create different visual effects.
| Feature | Radial Gradient | Linear Gradient |
|---|---|---|
| CSS function | radial-gradient() | linear-gradient() |
| Color direction | Outward from a center | Along a straight line |
| Common appearance | Circular or elliptical | Horizontal, vertical, or diagonal |
| Best use | Glows, spotlights, focal points | Section backgrounds, overlays, directional transitions |
| Position control | Center and shape | Angle or direction |
| Multiple colors | Supported | Supported |
For example, a linear gradient creates a transition from left to right:
background: linear-gradient(
90deg,
#667eea,
#764ba2
);
A radial gradient creates a transition outward from a central point:
background: radial-gradient(
circle,
#667eea,
#764ba2
);
Choose a radial gradient when you want to draw attention toward a specific area. Choose a linear gradient when you want a directional transition across a section.
You can also combine both functions in a layered background if the design benefits from both effects.
Common Mistakes When Creating Radial Gradient Backgrounds
Even though the radial-gradient() function is straightforward, a few common mistakes can make the result look different from what you expect.
1. Forgetting the background color underneath
Transparent gradients do not create an opaque color by themselves. If your design uses transparency, specify an appropriate base color.
.hero {
background:
radial-gradient(
circle,
rgba(59, 130, 246, 0.4),
transparent 70%
),
#0f172a;
}
2. Using too many colors
Too many unrelated colors can make a background look busy. Start with two complementary colors and add more only when they serve a clear design purpose.
3. Ignoring text contrast
A beautiful gradient is not useful if visitors cannot read the text placed on it.
Use a contrast checker to verify important text combinations. For WCAG 2.2 Level AA, normal text generally requires a contrast ratio of at least 4.5:1, while large text generally requires at least 3:1. Check the text against the parts of the gradient where it appears, not just one representative color.
4. Choosing a gradient that does not fit the layout
A small circular glow may look attractive in a card but may not fill a wide hero section as intended. Try ellipse, adjust the sizing keyword, or change the center position.
5. Overlooking mobile layouts
A gradient that looks balanced on a desktop monitor may appear too intense or poorly positioned on a phone.
Use responsive CSS, percentage-based positioning, and browser testing to refine the result at different viewport sizes.
6. Repeating CSS unnecessarily
If multiple elements use the same gradient, consider defining a reusable CSS class or custom property. This makes future changes easier and helps keep your stylesheet organized.
Best Practices for Using CSS Radial Gradients
Follow these recommendations to create attractive, maintainable gradient backgrounds.
Use your brand colors. Choose colors that match your site's visual identity instead of introducing unrelated shades.
Keep the focal point intentional. Place the brightest color near the content or feature you want visitors to notice.
Use transparency carefully. Transparent stops help you blend gradients into solid backgrounds or other background layers.
Prioritize accessibility. Test text contrast over the full gradient area, especially for headings, links, and buttons.
Prefer CSS over decorative image files when appropriate. A simple gradient can replace a static background image, reducing the need for an additional asset. However, complex textures and detailed illustrations may still require images.
Test performance on real devices. Simple gradients are generally inexpensive, but large numbers of layered effects can increase rendering work. Keep the design as simple as practical.
Make backgrounds responsive. Use flexible layouts, percentages, and responsive typography so the gradient complements the content at different screen sizes.
Keep your CSS reusable. Store repeated colors in CSS custom properties when maintaining a consistent palette across multiple pages.
For example:
:root {
--color-glow: #3b82f6;
--color-background: #0f172a;
}
.hero {
background: radial-gradient(
circle at 50% 30%,
color-mix(in srgb, var(--color-glow), transparent 35%),
transparent 65%
),
var(--color-background);
}
This example uses color-mix() to create a partially transparent version of the glow color. If you need to support older browsers, consider using an explicit rgba() color instead.
Frequently Asked Questions About CSS Radial Gradients
1. How do I create a radial gradient background in CSS?
Use the radial-gradient() function in the CSS background property.
body {
background: radial-gradient(
circle,
#ff7e5f,
#feb47b
);
}
The first color appears near the center, and the second color appears toward the gradient's outer edge.
2. What is the difference between radial-gradient() and linear-gradient()?
A radial gradient spreads outward from a central point in a circular or elliptical pattern. A linear gradient transitions between colors along a straight line, such as from left to right or from top to bottom.
3. How do I make a circular gradient in CSS?
Include the circle keyword after radial-gradient().
background: radial-gradient(
circle,
#ffffff,
#2563eb
);
This creates a circular gradient instead of the default elliptical shape.
4. How do I change the center of a radial gradient?
Use the at keyword followed by a position.
background: radial-gradient(
circle at 25% 25%,
#f9a8d4,
#7c3aed
);
The gradient's center is positioned 25% from the left and 25% from the top of the element.
5. Can I use more than two colors in a radial gradient?
Yes. You can specify as many color stops as your design requires.
background: radial-gradient(
circle,
#fef08a,
#fb923c,
#ec4899,
#7c3aed
);
For smoother control, assign percentage positions to individual color stops.
6. Can I make a radial gradient transparent?
Yes. Use transparent colors or colors with an alpha channel.
background: radial-gradient(
circle,
rgba(59, 130, 246, 0.7),
transparent 70%
);
This creates a blue glow that gradually fades into the background underneath it.
7. How do I make a radial gradient cover the entire screen?
Apply the gradient to the body element and give it a minimum height of 100vh.
body {
margin: 0;
min-height: 100vh;
background: radial-gradient(
ellipse at center,
#93c5fd,
#1e3a8a
);
}
For content that extends beyond the viewport, the body can grow with the page while maintaining its background.
8. Can I combine multiple radial gradients in CSS?
Yes. Separate each gradient with a comma and place the desired base color at the end.
background:
radial-gradient(circle at top left, #60a5fa, transparent 40%),
radial-gradient(circle at bottom right, #c084fc, transparent 40%),
#111827;
This creates two colored highlights over a dark background.
9. Are CSS radial gradients supported by modern browsers?
The radial-gradient() function is supported by all major modern browsers, including current versions of Chrome, Firefox, Safari, and Edge. Newer color functions used inside gradients may have different compatibility requirements, so check support if your project targets older browsers.
10. Do radial gradients affect website performance?
Simple CSS radial gradients are generally efficient and do not require downloading a separate background image. However, many overlapping gradients or complex animated effects can increase rendering work. For most static backgrounds, using a few well-designed gradients is a practical approach.
Conclusion
Learning how to make a radial gradient background in CSS gives you a flexible way to create modern, visually engaging website designs without relying on external images. With the radial-gradient() function, you can control the gradient's shape, size, position, and color transitions using just a few lines of CSS.
Start with a simple two-color gradient, then experiment with additional color stops, custom positioning, transparency, and layered backgrounds. For website hero sections, subtle glows and carefully positioned gradients can add depth while keeping the main content easy to read.
Remember that a good gradient should support your website's purpose rather than distract from it. Use your brand colors, check text contrast, test responsive layouts, and avoid unnecessary complexity.
With these techniques, you can create attractive radial gradient backgrounds for landing pages, cards, portfolios, dashboards, and many other web design projects.