Pie charts are circular charts divided into slices to illustrate numerical proportions. Each slice represents a part of a whole — commonly used to visualize data distribution (e.g., market share, budget percentage, survey results).
Even though CSS is not designed primarily for data visualization, you can create pie-chart-like shapes using just CSS — mainly by leveraging borders, clip-path, and conic-gradient.
A pie chart:
Example:
| Category | Percentage |
|---|---|
| A | 40% |
| B | 30% |
| C | 20% |
| D | 10% |
conic-gradient() (Modern & Simple)This is the easiest and most modern way to create a pie chart.
<div class="pie"></div>
<style>
.pie {
width: 200px;
height: 200px;
border-radius: 50%;
background: conic-gradient(
#4caf50 0 40%, /* 40% */ #2196f3 40% 70%,/* next 30% */ #ff9800 70% 90%,/* next 20% */ #f44336 90% 100% /* last 10% */ );
}
</style>
✔️ Best method
✔️ Pure CSS
✔️ Easy to adjust slices
❌ Not supported in very old browsers
clip-pathYou can manually build slices and rotate them.
<div class="chart">
<div class="slice slice1"></div>
<div class="slice slice2"></div>
</div>
<style>
.chart {
width: 200px;
height: 200px;
border-radius: 50%;
position: relative;
overflow: hidden;
}
.slice {
position: absolute;
width: 100%;
height: 100%;
clip-path: polygon(50% 50%, 100% 0, 100% 100%);
}
.slice1 {
background: orange;
transform: rotate(0deg);
}
.slice2 {
background: blue;
transform: rotate(120deg);
}
</style> ✔️ Works without gradients
❌ Hard to calculate angles manually
Uses thick borders to simulate pie slices. Rarely used now but good to know:
<div class="pie"></div>
<style>
.pie {
width: 0;
height: 0;
border: 100px solid;
border-color: #4caf50 #2196f3 transparent transparent;
border-radius: 50%;
}
</style> ✔️ Legacy technique
❌ Limited slices
❌ Hard to customize
| Method | Best Use Case |
|---|---|
conic-gradient() | Real pie charts, dashboards, modern apps |
clip-path | Controlled custom slices, animations |
| Border trick | Learning / old browsers / simple shapes |
| Approach | Ease | Notes |
|---|---|---|
conic-gradient | ⭐⭐⭐⭐⭐ | Best & easiest |
clip-path | ⭐⭐⭐⭐ | More control |
| Border hack | ⭐⭐⭐ | Old method |
Latest tech news and coding tips.
Learn on the Go. Download the Codeflare Mobile from iOS App Store. 1. What is…
Download the Codeflare iOS app and learn on the Go 1. What UI and UX…
1. Running Everything as Root One of the biggest beginner errors. Many new users log…
A keylogger is a type of surveillance software or hardware that records every keystroke made…
In JavaScript, it’s commonly used for: Recursive functions (like Fibonacci) Heavy calculations Repeated API/data processing…
For years, responsive design has depended almost entirely on media queries. We ask questions like: “If…