conic-gradient()
Example
.pie {
border-radius: 50%;
background: conic-gradient(tomato, gold, teal);
}.pie {
aspect-ratio: 1;
border-radius: 50%;
background: conic-gradient(
tomato 0 40%, gold 40% 75%, teal 75% 100%
);
}Hard stops at shared positions turn a smooth color sweep into clear pie slices.
Common mistakes
- Slices blend into each other because the stops are not doubled at the same angle.
- The chart starts from the wrong side; the gradient begins at the top unless
fromis set.
Key points
- Pie slices use hard stops, where each color starts at the previous color's end.
- A round pie sets
border-radius: 50%and equal width and height, oraspect-ratio: 1. - Charts drawn with gradients have a text or ARIA alternative, since the gradient carries no data for screen readers.
Interview questions
Where does a conic gradient start?
At the top, going clockwise. Use from <angle> to rotate the start, for example from 90deg.
conic-gradient vs radial-gradient?
A conic gradient changes color around a center point. A radial gradient changes color outward from the center.