CSS Gradient Generator
Create beautiful CSS gradients with live preview.
Understanding CSS Gradients
CSS gradients allow you to display smooth transitions between two or more colors without using images. Gradients are defined as CSS background images and can be used anywhere an image would work. There are three types of gradients: linear gradients (going down/up/left/right/diagonally), radial gradients (defined by their center), and conic gradients (rotated around a center point).
This generator focuses on linear and radial gradients, which are the most commonly used in modern web design. Gradients can create depth, visual interest, and modern aesthetics while maintaining excellent performance since they're rendered by CSS rather than loaded as image files.
Linear Gradients
Linear gradients transition colors along a straight line. You define the starting point and direction (or angle), and CSS smoothly transitions between your color stops.
Basic Linear Gradient Syntax
/* Simple top to bottom gradient */
background: linear-gradient(to bottom, #3498db, #2ecc71);
/* Horizontal gradient */
background: linear-gradient(to right, #e74c3c, #f39c12);
/* Diagonal gradient */
background: linear-gradient(to bottom right, #9b59b6, #3498db);
/* Using angle (0deg = to top, 90deg = to right) */
background: linear-gradient(45deg, #1abc9c, #3498db);
Multiple Color Stops
You can add multiple colors to create more complex gradients:
/* Three color gradient */
background: linear-gradient(to right, #667eea 0%, #764ba2 50%, #f093fb 100%);
/* Rainbow gradient */
background: linear-gradient(to right,
red, orange, yellow, green, blue, indigo, violet);
/* Color stops at specific positions */
background: linear-gradient(to bottom,
#3498db 0%,
#2ecc71 30%,
#f39c12 70%,
#e74c3c 100%);
Common Linear Gradient Directions
| Direction | Description | Alternative (Angle) |
|---|---|---|
to bottom |
Top to bottom (default) | 180deg |
to top |
Bottom to top | 0deg |
to right |
Left to right | 90deg |
to left |
Right to left | 270deg |
to bottom right |
Top-left to bottom-right | 135deg |
Radial Gradients
Radial gradients transition colors from a center point outward in a circular or elliptical shape. They're perfect for spotlight effects, buttons, and creating depth.
Basic Radial Gradient Syntax
/* Simple radial gradient (circle) */
background: radial-gradient(circle, #3498db, #2c3e50);
/* Elliptical gradient (default) */
background: radial-gradient(ellipse, #e74c3c, #c0392b);
/* Gradient with size */
background: radial-gradient(circle at center, #3498db 0%, #2c3e50 100%);
/* Positioned gradient */
background: radial-gradient(circle at top left, #1abc9c, #16a085);
Radial Gradient Positioning
/* Gradient centered at top */
background: radial-gradient(circle at top, white, blue);
/* Gradient in bottom right corner */
background: radial-gradient(circle at bottom right, yellow, red);
/* Gradient at specific position */
background: radial-gradient(circle at 30% 70%, green, darkgreen);
/* Multiple radial gradients */
background:
radial-gradient(circle at 20% 50%, rgba(255,255,255,0.5), transparent),
radial-gradient(circle at 80% 50%, rgba(255,255,255,0.5), transparent),
#3498db;
Practical Use Cases
1. Hero Section Backgrounds
.hero {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 100px 0;
color: white;
}
2. Button Hover Effects
.button {
background: linear-gradient(to right, #3498db, #2980b9);
transition: all 0.3s ease;
}
.button:hover {
background: linear-gradient(to right, #2980b9, #21618c);
}
3. Card Overlays
.card-overlay {
background: linear-gradient(
to bottom,
transparent 0%,
rgba(0,0,0,0.7) 100%
);
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 50%;
}
4. Loading Animations
@keyframes shimmer {
0% {
background-position: -1000px 0;
}
100% {
background-position: 1000px 0;
}
}
.loading {
background: linear-gradient(
to right,
#f6f7f8 0%,
#edeef1 20%,
#f6f7f8 40%,
#f6f7f8 100%
);
background-size: 1000px 100%;
animation: shimmer 2s infinite;
}
5. Text Gradients
.gradient-text {
background: linear-gradient(to right, #667eea, #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
font-size: 48px;
font-weight: bold;
}
Advanced Gradient Techniques
Repeating Gradients
Create patterns with repeating gradients:
/* Striped background */
background: repeating-linear-gradient(
45deg,
#606dbc,
#606dbc 10px,
#465298 10px,
#465298 20px
);
/* Repeating radial gradient */
background: repeating-radial-gradient(
circle,
#3498db,
#3498db 10px,
#2980b9 10px,
#2980b9 20px
);
Gradient Borders
.gradient-border {
border: 5px solid transparent;
background:
linear-gradient(white, white) padding-box,
linear-gradient(to right, #667eea, #764ba2) border-box;
border-radius: 10px;
}
Combining Multiple Gradients
.multi-gradient {
background:
linear-gradient(217deg, rgba(255,0,0,.8), rgba(255,0,0,0) 70.71%),
linear-gradient(127deg, rgba(0,255,0,.8), rgba(0,255,0,0) 70.71%),
linear-gradient(336deg, rgba(0,0,255,.8), rgba(0,0,255,0) 70.71%);
}
Browser Compatibility
Modern gradient syntax is well-supported, but you may need vendor prefixes for older browsers:
| Browser | Support | Prefix Needed |
|---|---|---|
| Chrome 26+ | Full support | No |
| Firefox 16+ | Full support | No |
| Safari 6.1+ | Full support | -webkit- for older versions |
| IE 10+ | Full support | No |
| Edge | Full support | No |
Performance Considerations
- Faster than images: Gradients are rendered by CSS, no HTTP requests needed
- Scalable: Look perfect at any resolution
- Animatable: Can be animated with CSS transitions
- Small file size: No impact on page load time
- GPU acceleration: Modern browsers use hardware acceleration
Design Tips
Creating Beautiful Gradients:
- Use similar hues: Gradients between similar colors look more natural
- Limit color stops: 2-3 colors usually look best
- Consider contrast: Ensure text is readable on gradient backgrounds
- Subtle is better: Gentle gradients often work better than bold ones
- Test on devices: Gradients may look different on various screens
- Use transparency: RGBA colors create depth and layers
Common Mistakes to Avoid
- Too many colors: Can look muddy and unprofessional
- Harsh transitions: Very different hues can create ugly mid-tones
- Ignoring accessibility: Ensure sufficient contrast for text
- Overusing gradients: Use sparingly for maximum impact
- Forgetting fallbacks: Always provide solid color fallback
Gradient Resources and Inspiration
- uiGradients: Beautiful gradient collection
- Gradient Hunt: Curated gradient palettes
- WebGradients: 180+ linear gradients
- Grabient: Interactive gradient tool
- CSS Gradient: Advanced gradient generator
Quick Reference
Linear Gradient:
linear-gradient(direction, color1, color2)
Radial Gradient:
radial-gradient(shape, color1, color2)
Angles:
- 0deg = to top
- 90deg = to right
- 180deg = to bottom
- 270deg = to left