Master linear, radial, and conic gradients to create stunning black backgrounds and modern designs with pure CSS.
CSS gradients are smooth transitions between two or more colors. They're created dynamically by the browser, making them resolution-independent and perfect for responsive design. Unlike images, gradients load instantly and can be easily customized.
Transitions along a straight line
linear-gradient()
Transitions from a center point
radial-gradient()
Transitions around a center point
conic-gradient()
Linear gradients transition colors along a straight line. They're the most commonly used gradient type and perfect for creating depth in black backgrounds.
/* Basic syntax */
background: linear-gradient(direction, color-stop1, color-stop2, ...);
/* Direction options */
background: linear-gradient(to bottom, #000, #333); /* Top to bottom */
background: linear-gradient(to right, #000, #111); /* Left to right */
background: linear-gradient(45deg, #000, #222); /* Angle in degrees */
background: linear-gradient(0.25turn, #000, #333); /* Angle in turns */
/* Multiple color stops */
background: linear-gradient(to right, #000 0%, #111 50%, #000 100%);
background: linear-gradient(to bottom, #000, #333);
background: linear-gradient(135deg, #000 0%, #222 50%, #000 100%);
background: linear-gradient(to right, #000, transparent);
background: linear-gradient(45deg,
#000 25%, #111 25%, #111 50%,
#000 50%, #000 75%, #111 75%);
background: linear-gradient(180deg,
#000 0%,
#0a0a0a 20%,
#111 40%,
#0a0a0a 60%,
#000 100%
);
background: repeating-linear-gradient(
45deg,
#000,
#000 10px,
#111 10px,
#111 20px
);
Radial gradients transition colors from a center point outward. They're perfect for creating spotlight effects, vignettes, and depth in black backgrounds.
/* Basic syntax */
background: radial-gradient(shape size at position, color-stop1, color-stop2, ...);
/* Shape options */
background: radial-gradient(circle, #000, #333); /* Circle shape */
background: radial-gradient(ellipse, #000, #111); /* Ellipse shape (default) */
/* Size keywords */
background: radial-gradient(circle closest-side, #000, #333);
background: radial-gradient(ellipse farthest-corner, #000, #111);
/* Position */
background: radial-gradient(circle at center, #000, #333);
background: radial-gradient(circle at top left, #000, #111);
background: radial-gradient(circle at 20% 80%, #000, #222);
background: radial-gradient(circle, #333 0%, #000 70%);
background: radial-gradient(ellipse at top, #222 0%, #000 50%);
background: radial-gradient(circle at 30% 30%, #333, #000 50%);
background: radial-gradient(circle closest-side,
transparent 50%, #000 50%);
.vignette {
background:
radial-gradient(
ellipse at center,
transparent 0%,
rgba(0,0,0,0.4) 40%,
rgba(0,0,0,0.8) 100%
),
#222;
}
background:
radial-gradient(circle at 20% 50%,
rgba(255,255,255,0.1) 0%, transparent 50%),
radial-gradient(circle at 80% 50%,
rgba(255,255,255,0.05) 0%, transparent 50%),
#000;
Conic gradients transition colors around a center point, creating pie-chart-like effects. They're great for creating unique black background patterns.
/* Basic syntax */
background: conic-gradient(from angle at position, color-stop1, color-stop2, ...);
/* Simple conic gradient */
background: conic-gradient(#000, #333, #000);
/* With starting angle */
background: conic-gradient(from 45deg, #000, #111, #000);
/* With position */
background: conic-gradient(at 30% 30%, #000, #333, #000);
/* Complete syntax */
background: conic-gradient(from 90deg at 25% 25%, #000 0deg, #333 180deg, #000 360deg);
background: conic-gradient(#000, #333, #000);
background: conic-gradient(from 45deg,
#000 0deg, #111 90deg, #000 180deg,
#111 270deg, #000 360deg);
background: repeating-conic-gradient(
#000 0deg 30deg,
#111 30deg 60deg
);
background: conic-gradient(at 40% 40%,
#000, #222 20%, #000 40%,
#222 60%, #000 80%, #222);
Combine multiple gradients to create sophisticated black background patterns without using images.
.carbon-fiber {
background:
linear-gradient(27deg, #151515 5px, transparent 5px) 0 5px,
linear-gradient(207deg, #151515 5px, transparent 5px) 10px 0px,
linear-gradient(27deg, #222 5px, transparent 5px) 0px 10px,
linear-gradient(207deg, #222 5px, transparent 5px) 10px 5px,
linear-gradient(90deg, #1b1b1b 10px, transparent 10px),
linear-gradient(#1d1d1d 25%, #1a1a1a 25%, #1a1a1a 50%,
transparent 50%, transparent 75%, #242424 75%, #242424);
background-color: #131313;
background-size: 20px 20px;
}
.mesh-gradient {
background-color: #000;
background-image:
radial-gradient(at 47% 33%, #212121 0%, transparent 59%),
radial-gradient(at 82% 65%, #111111 0%, transparent 55%);
}
.dotted-grid {
background-color: #000;
background-image:
radial-gradient(circle, #333 1px, transparent 1px);
background-size: 20px 20px;
}
.diagonal-stripes {
background: repeating-linear-gradient(
45deg,
#000,
#000 10px,
#111 10px,
#111 20px
);
}
CSS gradients are generally performant, but following best practices ensures optimal rendering.
:root {
--gradient-start: #000;
--gradient-end: #333;
--gradient-angle: 135deg;
}
.dynamic-gradient {
background: linear-gradient(
var(--gradient-angle),
var(--gradient-start),
var(--gradient-end)
);
}
/* Dark mode adjustment */
@media (prefers-color-scheme: dark) {
:root {
--gradient-start: #000;
--gradient-end: #111;
}
}
Quick reference for gradient syntax:
deg
- Degrees (0-360)turn
- Full rotation (0-1)rad
- Radians%
- Position along gradientControl gradient transitions:
/* Smooth transition */
background: linear-gradient(#000, #333);
/* Sharp transition */
background: linear-gradient(
#000 50%, #333 50%
);
Tips for troubleshooting:
Create custom black gradients with our visual tool
Open Gradient GeneratorGradient Type | Chrome | Firefox | Safari | Edge | Mobile Support |
---|---|---|---|---|---|
linear-gradient | 26+ | 16+ | 6.1+ | 12+ | Excellent |
radial-gradient | 26+ | 16+ | 6.1+ | 12+ | Excellent |
conic-gradient | 69+ | 83+ | 12.1+ | 79+ | Good |
repeating-*-gradient | 26+ | 16+ | 6.1+ | 12+ | Excellent |
/* Fallback approach */
.gradient-bg {
/* Fallback for old browsers */
background: #000;
/* Modern browsers */
background: linear-gradient(135deg, #000 0%, #333 100%);
}
/* Feature detection */
@supports (background: conic-gradient(#000, #333)) {
.conic-bg {
background: conic-gradient(#000, #333, #000);
}
}
Inspiring examples of black gradients in web design
Subtle depth for hero sections
Elevated card effect
Interactive button style
Gradient text effect