Flat design has its place, but gradients bring life to interfaces. From subtle depth effects to bold statement backgrounds, gradients are a powerful tool in every designer's toolkit. Let's explore how to create them with CSS.
The Three Types of CSS Gradients
CSS supports three gradient types, each creating different visual effects:
- Linear gradients: Colors transition along a straight line
- Radial gradients: Colors radiate from a center point
- Conic gradients: Colors rotate around a center point
Linear Gradients
The most common type. Colors blend from one point to another along a line.
/* Basic two-color gradient */ background: linear-gradient(to right, #667eea, #764ba2); /* With angle */ background: linear-gradient(135deg, #667eea, #764ba2); /* Multiple color stops */ background: linear-gradient(90deg, #ff6b6b, #feca57, #48dbfb);
Direction Options
to top,to bottom(default),to left,to rightto top right,to bottom left, etc.- Angles:
0deg(up),90deg(right),180deg(down),270deg(left)
Radial Gradients
Colors emanate from a center point outward, creating circular or elliptical patterns.
/* Basic radial */ background: radial-gradient(circle, #667eea, #764ba2); /* Ellipse (default shape) */ background: radial-gradient(ellipse, #667eea, #764ba2); /* Positioned center */ background: radial-gradient(circle at top left, #667eea, #764ba2);
Conic Gradients
Colors rotate around a center point like a color wheel. Great for pie charts and decorative effects.
/* Color wheel effect */ background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red); /* Pie chart segment */ background: conic-gradient(#667eea 0deg 90deg, #764ba2 90deg 360deg);
Color Stops and Control
You can precisely control where colors start, stop, and transition:
/* Hard color stops (no blending) */ background: linear-gradient(90deg, #667eea 0%, #667eea 50%, #764ba2 50%, #764ba2 100%); /* Controlled transition points */ background: linear-gradient(90deg, #667eea 0%, #667eea 25%, #764ba2 75%, #764ba2 100%);
Popular Gradient Techniques
Gradient Text
.gradient-text {
background: linear-gradient(135deg, #667eea, #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
Gradient Borders
.gradient-border {
border: 3px solid transparent;
background: linear-gradient(white, white) padding-box,
linear-gradient(135deg, #667eea, #764ba2) border-box;
}
Overlay on Images
.image-overlay {
background: linear-gradient(
to bottom,
rgba(0,0,0,0) 0%,
rgba(0,0,0,0.8) 100%
), url('image.jpg');
}
Performance Tip: Gradients are rendered by the browser and scale perfectly without quality loss. They're often more performant than image backgrounds, especially for simple patterns.
Color Harmony in Gradients
Not all color combinations work well as gradients. Follow these principles:
- Analogous colors: Adjacent on the color wheel, always safe (blue → purple)
- Complementary: Opposite on the wheel, use carefully (orange → blue can look muddy in the middle)
- Monochromatic: Same hue, different lightness/saturation (safe and elegant)
- Avoid muddy midpoints: When mixing across the color wheel, the middle can turn gray/brown
Accessibility Considerations
- Don't rely on gradient color alone to convey information
- Ensure sufficient contrast if placing text over gradients
- Test with colorblind simulation tools
- Consider users with motion sensitivity when animating gradients
Create Beautiful Gradients
Visual gradient generator with live preview and CSS code export.
Open Gradient Generator →Conclusion
Gradients are one of CSS's most powerful features for adding visual polish without images. Start simple, experiment with color combinations, and remember that subtle gradients often work better than dramatic ones. Your designs will thank you.