Skip to content
Related Articles

Related Articles

Improve Article

How to create a Pie Chart using HTML & CSS ?

  • Last Updated : 11 Jun, 2020

Pie Chart is a type of graph that displays data in a circular shape and is generally used to show percentage or proportional data. The percentage represented in the graph by each category is provided near the corresponding slice of one portion of pie chart. These charts are very good for displaying data for two or more categories.

HTML Code: In the following code, the basic design or structure is shown.

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
      "width=device-width, initial-scale=1.0">
    <title>Pie Chart</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <h1>Pie Chart</h1>
    <div class="piechart"></div>
</body>
</html>

CSS Code: In the following section, the design of pie-chart is demonstrated using some CSS properties.




<style>
    .piechart {
        margin-top: 300px;
        display: block;
        position: absolute;
        width: 400px;
        height: 400px;
        border-radius: 50%;
        background-image: conic-gradient(
            pink 70deg, 
            lightblue 0 235deg, 
            orange 0);
    }
  
    body,
    .piechart {
        display: flex;
        justify-content: center;
        align-items: center;
    }
</style>

Complete Code:




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
  
    <title>Pie Chart</title>
  
    <style>
        .piechart {
            margin-top: 300px;
            display: block;
            position: absolute;
            width: 400px;
            height: 400px;
            border-radius: 50%;
            background-image: conic-gradient(
                pink 70deg, 
                lightblue 0 235deg, 
                orange 0);
        }
  
        body,
        .piechart {
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
</head>
  
<body>
    <h1>Pie Chart</h1>
    <div class="piechart"></div>
</body>
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :