CSS Gradients
CSS Gradients are smooth transitions between multiple colors, created using linear-gradient(), radial-gradient(), or conic-gradient() functions to generate background images without external files.
How do you make a gradient in CSS?
Use a gradient function as a background image: background: linear-gradient(to right, #3b82f6, #8b5cf6);. linear-gradient() blends along a line, radial-gradient() from a centre point outward, and conic-gradient() around a centre, like a pie chart. You can add as many colour stops as you like, each with an optional position.
.hero { background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%); }
.spot { background: radial-gradient(circle at top left, #fde68a, transparent 60%); }
.pie { background: conic-gradient(#3b82f6 0 40%, #e5e7eb 0); border-radius: 50%; }
.title {
background: linear-gradient(90deg, #f97316, #db2777);
-webkit-background-clip: text; background-clip: text;
color: transparent;
}Interactive CSS Gradients Demo
Code Editor
<div class="box linear">linear-gradient</div>
<div class="box radial">radial-gradient</div>
<div class="box conic">conic-gradient</div>
<h2 class="text">Gradient text</h2>Preview
Linear Gradients Fundamentals
Linear gradients create smooth transitions between colors along a straight line. They're perfect for backgrounds, buttons, and creating depth in flat designs.
Linear Gradient Syntax
background: linear-gradient(direction, color1, color2, ...);
background: linear-gradient(45deg, #667eea, #764ba2);
background: linear-gradient(to right, #f093fb 0%, #f5576c 100%);Direction: to right, to bottom, 45deg, etc.
Colors: Any valid CSS color format
Color Stops: Precise positioning with percentages
Multiple Colors: Unlimited color transitions
Radial & Conic Gradients
Radial gradients radiate from a center point, while conic gradients sweep around a circle. Both create unique visual effects for modern web designs.
Radial Gradients
radial-gradient(circle at center, #667eea, #764ba2)- • Perfect for spotlights and focus effects
- • Can be positioned anywhere
- • Supports ellipse and circle shapes
Conic Gradients
conic-gradient(from 0deg, #667eea, #764ba2, #667eea)- • Great for pie charts and color wheels
- • 360-degree color transitions
- • Can start from any angle
Advanced Gradient Techniques
Gradient Text
Apply gradients to text using background-clip: text for eye-catching typography.
Layered Gradients
Combine multiple gradients for complex, multi-dimensional effects.
Repeating Patterns
Create stripes, patterns, and textures with repeating gradients.
Performance & Best Practices
Best Practices
- • Use gradients purposefully, not as decoration
- • Maintain sufficient contrast for accessibility
- • Consider color theory and brand consistency
- • Test gradients across different devices
- • Provide fallback colors for older browsers
Performance Tips
- • Prefer CSS gradients over image files
- • Limit complex multi-layer gradients
- • Use will-change for animated gradients
- • Consider GPU acceleration for smooth animations
- • Optimize color stops for file size
Common Use Cases
UI Components
- • Button hover states and call-to-actions
- • Header backgrounds and hero sections
- • Card overlays and image masks
Data Visualization
- • Progress bars and loading indicators
- • Chart backgrounds and heat maps
- • Status indicators and badges
Brand Elements
- • Logo backgrounds and brand colors
- • Section dividers and decorative elements
- • Themed interfaces and color schemes
Interactive Effects
- • Hover transitions and focus states
- • Loading animations and progress feedback
- • Dynamic backgrounds and themes
CSS Gradients — step by step
linear-gradient()
Create smooth color transitions along a straight line: linear-gradient(to right, #3b82f6, #8b5cf6). Specify direction with keywords or angles like 45deg.
🎯 Quick Check
Which gradient function creates a cone-like sweep of colors around a center point?
CSS Gradients: summary
Key points
- Gradients are images, so they work in
background-imageandborder-image, and can layer over photos. - Two stops at the same position create a hard edge, which is how stripes are made.
repeating-linear-gradient()tiles a pattern.- Interpolating in
oklch(linear-gradient(in oklch, …)) avoids the muddy grey middle between some colours.
Frequently asked questions
›How do I make gradient text?
Apply the gradient as a background, then add background-clip: text (with the -webkit- prefix) and color: transparent.
›Can I animate a gradient?
Gradients can't be transitioned directly. Animate background-position on an oversized gradient, or animate a registered custom property (@property) used inside the gradient.