Gradients are one of the most versatile design tools in CSS. They can transform a flat background into something rich and atmospheric, guide the user's eye, reinforce brand identity, and add depth without increasing page weight. Yet many developers rely on copy-pasting gradient snippets from CodePen or older projects without truly understanding how they work.
This guide covers the three types of CSS gradients — linear, radial, and conic — with practical examples, color theory tips, and advice on creating gradients that look polished and perform well. When you are ready to build your own, our CSS gradient generator tool makes it easy to design gradients visually and copy the resulting code.
Before diving into syntax, it is worth understanding why CSS gradients deserve a place in your design toolkit:
A linear gradient transitions colors along a straight line. This is the most common gradient type and the one you will use most often.
background-image: linear-gradient(direction, color1, color2);
The direction can be specified as a keyword or an angle:
| Value | Direction |
|---|---|
to right | Left to right |
to left | Right to left |
to bottom | Top to bottom (default) |
to top | Bottom to top |
to bottom right | Top-left to bottom-right |
45deg | 45-degree angle |
135deg | 135-degree angle (diagonal) |
A simple two-color gradient from purple to pink:
background-image: linear-gradient(to right, #8b5cf6, #ec4899);
A diagonal gradient with three colors:
background-image: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
Color stops let you control exactly where each color appears in the gradient. By default, colors are evenly distributed, but you can override this with percentage or length values:
/* 70% of the gradient is the first color, then a sharp transition */
background-image: linear-gradient(to right, #8b5cf6 70%, #ec4899);
/* Multiple stops for a banded effect */
background-image: linear-gradient(to right, #8b5cf6 0%, #8b5cf6 20%, #06b6d4 20%, #06b6d4 40%, #8b5cf6 40%);
A radial gradient transitions colors outward from a center point, creating a circular or elliptical shape. These are ideal for spotlight effects, vignettes, and adding depth.
background-image: radial-gradient(shape size at position, color1, color2);
circle — the gradient radiates evenly in all directionsellipse — the gradient radiates along an ellipse (default)closest-side — reaches the nearest edge of the containerfarthest-side — reaches the farthest edgeclosest-corner — reaches the nearest cornerfarthest-corner — reaches the farthest corner (default)A centered radial gradient with a soft glow:
background-image: radial-gradient(circle at center, #8b5cf6, #0f1117);
An offset radial gradient for a spotlight effect:
background-image: radial-gradient(ellipse at 20% 50%, #1e1b4b, #0f1117);
A conic gradient transitions colors around a center point in a sweeping arc, similar to a color wheel or pie chart. This type is less commonly used but can create striking visual effects.
background-image: conic-gradient(from angle at position, color1, color2, ...);
A color wheel effect:
background-image: conic-gradient(#ef4444, #f59e0b, #22c55e, #3b82f6, #8b5cf6, #ef4444);
A pie chart using hard color stops:
background-image: conic-gradient(
#8b5cf6 0deg 120deg,
#06b6d4 120deg 240deg,
#f59e0b 240deg 360deg
);
border-radius: 50%;
Sometimes you want a gradient pattern to repeat, creating stripes or waves. CSS provides repeating-linear-gradient(), repeating-radial-gradient(), and repeating-conic-gradient() for this purpose.
background-image: repeating-linear-gradient(
45deg,
#1e1e2e 0px,
#1e1e2e 10px,
#2d2d3f 10px,
#2d2d3f 20px
);
background-image: repeating-radial-gradient(
circle at center,
#8b5cf6 0px,
transparent 20px,
transparent 30px
);
Using semi-transparent colors in gradients opens up powerful compositing possibilities. You can overlay gradients on images, create glass-like effects, and build layered depth.
/* Gradient overlay on a background image */
background-image: linear-gradient(to bottom, rgba(15, 17, 23, 0.8), rgba(15, 17, 23, 0.2)),
url('hero-image.jpg');
/* Glassmorphism-style gradient */
background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(6, 182, 212, 0.2));
backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.1);
rgba() or hsla() instead of the transparent keyword. The transparent keyword is actually rgba(0,0,0,0), which can cause a subtle dark edge during the transition. Using the same color at zero alpha avoids this.
Not all color combinations work well in gradients. Here are some guidelines for choosing colors that look professional:
Colors that sit next to each other on the color wheel create smooth, harmonious transitions. Think purple to blue, or orange to yellow.
/* Analogous: blue → indigo → violet */
background-image: linear-gradient(to right, #3b82f6, #6366f1, #8b5cf6);
Colors opposite each other on the color wheel create high contrast and visual energy. Use them sparingly or with transitional colors in between.
/* Complementary: purple → pink (with a warm middle tone) */
background-image: linear-gradient(to right, #8b5cf6, #d946ef, #ec4899);
Shades of the same hue create elegant, subtle gradients perfect for UI backgrounds and cards.
/* Monochromatic: dark → mid → light purple */
background-image: linear-gradient(to bottom, #1e1b4b, #312e81, #4c1d95);
For dark UIs, use deeply saturated colors against very dark backgrounds. Avoid going fully to pure black — dark blues, dark purples, and dark grays give gradients more life.
background-size with background-position animation instead of animating the gradient itself.background-image values for complex effects rather than nesting elements.background-color fallback for browsers that may not support certain gradient types.background shorthand incorrectly. The background shorthand can override your gradient. Use background-image explicitly for gradients.background-size. When using gradient patterns, set background-size to control how the pattern tiles.Stop writing gradient code by hand. Use our free CSS Gradient Generator to pick colors, adjust angles, preview results, and copy production-ready CSS in seconds.
Open CSS Gradient Generator →CSS gradients are a deceptively powerful design tool. With just a few lines of code, you can create atmospheres, guide attention, reinforce branding, and add polish to any web interface. By understanding linear, radial, and conic gradients — along with color theory and accessibility best practices — you can move beyond the basic two-color fade and create gradients that truly enhance your designs.
The fastest way to experiment is with a visual tool. Our CSS gradient generator lets you adjust every parameter in real time, see the result instantly, and copy the CSS with one click. Design gradients that look good, perform well, and work for everyone.