Conic Gradient Pie Chart Pure CSS
Render a pie chart using only CSS conic gradient with multiple segments and a transparent center for a donut effect.
Code
.pie-chart {
width: 200px;
height: 200px;
border-radius: 50%;
background: conic-gradient(
#e74c3c 0% 25%,
#f39c12 25% 50%,
#2ecc71 50% 75%,
#3498db 75% 100%
);
}
.donut-chart {
width: 200px;
height: 200px;
border-radius: 50%;
background: conic-gradient(
#e74c3c 0% 30%,
#f39c12 30% 55%,
#2ecc71 55% 80%,
#3498db 80% 100%
);
mask: radial-gradient(circle, transparent 60px, black 61px);
-webkit-mask: radial-gradient(circle, transparent 60px, black 61px);
}How it works
conic-gradient sweeps color stops around a center point — the mechanism behind the pie segments.
The rules target .pie-chart — each selector names the element it restyles, in source order.
Interactive Tools for This Topic
Aspect Ratio CalculatorSimplify a width-to-height ratio, show its decimal value, and derive a matching height for a new width.Border Radius PreviewPreview four-corner border-radius values on a live box and copy the generated shorthand border-radius CSS declaration.Box Shadow GeneratorBuild CSS box-shadow values with offset, blur, spread, color, opacity, and inset controls, with a live preview of the result.CSS Color Name LookupTranslate between CSS keyword color names and hex values with RGB and HSL conversions, exact name matching, and nearest-color suggestions.
FAQ
- Which elements does this stylesheet target?
- The rules bind to `.pie-chart`; when two rules tie in specificity, the one written later in the file wins.
Report a problem with this exampleOpens a pre-filled issue on GitHub.