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.

CssData Integrity

Code

csssnippet
25 lines
.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

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.