CSS Gradient Generator
Build linear and radial CSS gradients visually and copy the CSS code
Color stops
CSS output
background: linear-gradient(135deg, #6366f1 0%, #ec4899 100%);What Is a CSS Gradient?
A CSS gradient generator is a visual tool that helps you build smooth color transitions without writing gradient syntax by hand. In CSS, a gradient is a smooth transition between two or more colors, rendered directly by the browser without any image file. The CSS Image Module Level 4 specification defines gradient functions as a type of image value, which means they can appear anywhere a background-image, list-style-image, or border-image value is accepted. Because the browser rasterizes gradients at render time, they scale to any resolution and never produce blurry artifacts on high-DPI screens. Using a CSS gradient generator saves time and reduces guesswork β you adjust colors and positions visually, then copy the finished CSS rule.
CSS supports three main gradient shapes: linear (along a straight line), radial (outward from a center point), and conic (a sweep around a center point). Each shape accepts a list of color stops, where you specify the color and optionally a position (percentage or length). The browser interpolates colors between stops using the sRGB color space by default, though CSS Color Level 4 allows specifying other color spaces like oklch and lab for perceptually smoother transitions.
Gradients replace image-based backgrounds for most decorative purposes on the web. A single CSS rule produces what once required a Photoshop export and an HTTP request. They are resolution-independent, require zero network bandwidth beyond the CSS itself, and can be animated or transitioned with standard CSS properties. The gradient syntax has been stable across all major browsers since 2013, and the unprefixed form works in Chrome, Firefox, Safari, and Edge without fallbacks.
Why Use This CSS Gradient Generator?
Writing gradient syntax by hand means guessing at stop positions, checking angle values, and repeatedly refreshing to see the result. A visual builder lets you see the gradient as you build it, adjust stops by dragging, and copy the final CSS when it looks right.
CSS Gradient Generator Use Cases
CSS Gradient Types Reference
CSS defines five gradient functions. The three primary types (linear, radial, conic) each have a repeating variant that tiles the pattern. repeating-linear-gradient() and repeating-radial-gradient() are useful for striped backgrounds and concentric rings. All gradient functions accept color stops in any CSS color format: HEX, RGB, HSL, named colors, or oklch. Browser support for all five functions is effectively universal across Chrome, Firefox, Safari, and Edge β no vendor prefixes are required.
| Function | Example syntax | Direction | Common use |
|---|---|---|---|
| linear-gradient() | to right, #f00, #00f | Straight line | Backgrounds, hero sections, progress bars |
| radial-gradient() | circle, #f00, #00f | Outward from center | Spotlight effects, buttons, badges |
| conic-gradient() | from 0deg, #f00, #00f | Sweep around center | Pie charts, color wheels, spinners |
| repeating-linear | to right, #f00 0 10px, #00f 10px 20px | Tiled line | Stripes, progress indicators, decorative borders |
| repeating-radial | circle, #f00 0 10px, #00f 10px 20px | Tiled circle | Concentric ring patterns, retro textures |
Linear vs Radial vs Conic Gradients
Each gradient type maps colors to geometry differently. Choosing the right type depends on the visual effect you need, not on a quality difference between them. For most page backgrounds and section dividers, a linear gradient is the correct default β it is the simplest to reason about and the most predictable across elements of varying sizes. Radial and conic gradients are better reserved for specific visual effects where the circular or rotational geometry is meaningful rather than decorative.
Code Examples
Examples of generating and applying CSS gradients programmatically in JavaScript, Python, CSS, and Go. Each produces valid CSS gradient strings you can use directly in stylesheets or inline styles.
// Generate a CSS linear-gradient string from an array of stops
function buildGradient(angle, stops) {
const parts = stops.map(s => `${s.color} ${s.position}%`)
return `linear-gradient(${angle}deg, ${parts.join(', ')})`
}
const stops = [
{ color: '#6366f1', position: 0 },
{ color: '#ec4899', position: 50 },
{ color: '#f59e0b', position: 100 },
]
buildGradient(90, stops)
// -> "linear-gradient(90deg, #6366f1 0%, #ec4899 50%, #f59e0b 100%)"
// Apply to an element
document.querySelector('.hero').style.background = buildGradient(135, stops)# Generate a CSS gradient string for use in templates or SVGs
def build_gradient(angle: int, stops: list[tuple[str, int]]) -> str:
parts = [f"{color} {pos}%" for color, pos in stops]
return f"linear-gradient({angle}deg, {', '.join(parts)})"
stops = [("#6366f1", 0), ("#ec4899", 50), ("#f59e0b", 100)]
print(build_gradient(135, stops))
# -> "linear-gradient(135deg, #6366f1 0%, #ec4899 50%, #f59e0b 100%)"
# Interpolate N colors between two endpoints
def interpolate_hex(c1: str, c2: str, steps: int) -> list[str]:
r1, g1, b1 = int(c1[1:3], 16), int(c1[3:5], 16), int(c1[5:7], 16)
r2, g2, b2 = int(c2[1:3], 16), int(c2[3:5], 16), int(c2[5:7], 16)
return [
f"#{int(r1+(r2-r1)*i/(steps-1)):02x}"
f"{int(g1+(g2-g1)*i/(steps-1)):02x}"
f"{int(b1+(b2-b1)*i/(steps-1)):02x}"
for i in range(steps)
]
interpolate_hex("#6366f1", "#f59e0b", 4)
# -> ['#6366f1', '#9a7399', '#d18042', '#f59e0b']/* Linear gradient β left to right */
.hero {
background: linear-gradient(90deg, #6366f1 0%, #ec4899 50%, #f59e0b 100%);
}
/* Radial gradient β circular spotlight */
.badge {
background: radial-gradient(circle at 30% 30%, #6366f1, #312e81);
}
/* Conic gradient β color wheel */
.wheel {
background: conic-gradient(from 0deg, #ef4444, #f59e0b, #22c55e, #3b82f6, #8b5cf6, #ef4444);
border-radius: 50%;
}
/* Multi-stop with transparency */
.overlay {
background: linear-gradient(
to bottom,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.6) 60%,
rgba(0, 0, 0, 0.9) 100%
);
}
/* Repeating stripes */
.stripes {
background: repeating-linear-gradient(
45deg,
#6366f1 0 10px,
transparent 10px 20px
);
}package main
import "fmt"
// Stop represents one color stop in a gradient.
type Stop struct {
Color string
Position int // percent 0-100
}
func buildGradient(angle int, stops []Stop) string {
result := fmt.Sprintf("linear-gradient(%ddeg", angle)
for _, s := range stops {
result += fmt.Sprintf(", %s %d%%", s.Color, s.Position)
}
return result + ")"
}
func main() {
stops := []Stop{
{"#6366f1", 0},
{"#ec4899", 50},
{"#f59e0b", 100},
}
fmt.Println(buildGradient(135, stops))
// -> "linear-gradient(135deg, #6366f1 0%, #ec4899 50%, #f59e0b 100%)"
}