Published on April 11, 2026 · 6 min read
CSS gradients are one of the most versatile tools in a web developer's toolkit. They eliminate the need for image assets in backgrounds, buttons, and decorative elements, reducing page weight and improving rendering performance. But most developers only scratch the surface of what's possible. Let's go deeper.
A linear gradient transitions colors along a straight line. The syntax is straightforward, but the direction system catches people off guard.
/* Direction using keywords */
background: linear-gradient(to right, #8b5cf6, #06b6d4);
/* Direction using degrees (0° = bottom-to-top, clockwise) */
background: linear-gradient(135deg, #8b5cf6, #06b6d4, #10b981);
/* With hard color stops for striped effects */
background: linear-gradient(
45deg,
#1a1d2e 25%,
#8b5cf6 25% 50%,
#1a1d2e 50% 75%,
#8b5cf6 75%
);
background-size: 40px 40px;
Color stops can be positioned using percentages or length units. Unspecified stops are evenly distributed. A common pattern for subtle depth is placing a semi-transparent overlay:
/* Card with gradient overlay on background image */
.card {
background:
linear-gradient(180deg, transparent 40%, rgba(15,17,23,0.9) 100%),
url('hero-image.jpg');
background-size: cover;
}
Radial gradients emanate from a center point, creating circular or elliptical patterns. They're perfect for spotlight effects, vignettes, and creating the illusion of depth on flat surfaces.
/* Spotlight effect */
background: radial-gradient(circle at 30% 40%, #8b5cf6 0%, transparent 50%);
/* Vignette — subtle darkening at edges */
background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.4) 100%);
/* Multiple radial gradients for bokeh effect */
background:
radial-gradient(circle at 20% 30%, rgba(139,92,246,0.3) 0%, transparent 30%),
radial-gradient(circle at 70% 60%, rgba(6,182,212,0.2) 0%, transparent 25%),
radial-gradient(circle at 50% 80%, rgba(16,185,129,0.25) 0%, transparent 35%),
#0f1117;
Radial gradients accept size keywords that define the ending shape:
closest-side: Ends at the nearest side of the containerfarthest-corner: Extends to the farthest corner (default)circle at X Y: Precise center positioningConic gradients rotate colors around a center point, like a color wheel or pie chart. They're relatively new (2020+) but incredibly useful for specific patterns.
/* Pie chart using conic-gradient */
background: conic-gradient(
#8b5cf6 0% 35%, /* Purple: 35% */
#06b6d4 35% 60%, /* Cyan: 25% */
#10b981 60% 80%, /* Green: 20% */
#f59e0b 80% 100% /* Amber: 20% */
);
border-radius: 50%;
/* Conic gradient for a loading spinner */
background: conic-gradient(from 0deg, #8b5cf6, transparent);
animation: spin 1s linear infinite;
Repeating gradients create seamless patterns that would otherwise require SVG or raster images. This is where CSS gradients really shine for performance — no HTTP requests, no image decoding, just math rendered by the GPU.
/* Diagonal stripes */
background: repeating-linear-gradient(
45deg,
transparent,
transparent 10px,
rgba(139,92,246,0.1) 10px,
rgba(139,92,246,0.1) 20px
);
/* Dot pattern */
background: radial-gradient(
circle,
rgba(139,92,246,0.3) 1px,
transparent 1px
);
background-size: 20px 20px;
/* Checkerboard */
background:
conic-gradient(#1a1d2e 90deg, #22263a 90deg 180deg)
0 0 / 30px 30px;
background-image values instead of wrapper divs.background-position with gradients triggers repaints. Use transform and opacity where possible.will-change: background sparingly: It can actually hurt performance by promoting layers unnecessarily. Only use it when you've confirmed a paint bottleneck.Color stop order matters. linear-gradient(to right, blue, red) is not the same as linear-gradient(to left, blue, red). The gradient always transitions in the specified direction, from the first color to the last.
Percentage stops can create hard edges. Two adjacent stops at the same position (blue 50%, red 50%) create an instant transition instead of a smooth blend. This is actually useful for stripe patterns but catches people off guard when unintended.
Conic gradients need explicit center for consistent results. Without specifying at X Y, the center defaults to the center of the element, which changes if the element resizes.
CSS gradients replace image assets for most decorative backgrounds, reducing load times and simplifying maintenance. Linear gradients handle directional transitions, radial gradients create depth and spotlight effects, conic gradients build pie charts and spinners, and repeating gradients generate patterns — all without a single image file. Master these four types and you'll eliminate dozens of background images from your projects.