How to create an Area Chart using CSS ?
Last Updated :
26 Apr, 2025
In this article, we will see how to create Area charts using CSS. There are many Libraries available, which can help us to build area charts, although, here, we will be using pure HTML and CSS to create an Area Chart.
An Area Chart is a graphical representation of quantitative data where multiple data items are combined to form a graph.
The above diagram represents the basic area chart in the XY-plane with 4 data items. Now, we will create a similar area chart with the below approach.
Steps to create an Area Chart:
- To create an area chart, we will use <div> tag & put the class name as “area_chart”. After that, we will apply CSS using that class selector on this div to make it like XY Plane. In the example code snippet, we have used a <div> tag with 4 <div/> children
<div class="area_chart">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
- Every div inside is a data item. We will be adding the shape to every Item. For this, we can use custom properties as they can be easily accessed within CSS. Here, –top_left is the point on the left top, and –top_right is the point on the right top of the Item shape.
<div class="area_chart">
<div style="--top_left: 0.9; --top_right: 0.6;"></div>
<div style="--top_left: 0.6; --top_right: 0.4;"></div>
<div style="--top_left: 0.4; --top_right: 0.5;"></div>
<div style="--top_left: 0.5; --top_right: 0.2;"></div>
</div>
- Now, we can shape the parent div with the area_chart class, by implementing the different styles in the class. We are keeping the width: 700px & height: 400px.
.area_chart {
width: 700px;
height:400px;
display: flex;
}
- Finally, we will clip each and every item. The clip-path property is used to clip the particular section of the image or specific shape such that part of the shape inside the section is shown and part of the shape outside the section is not shown.
clip-path: polygon(
0% calc(100% * var(--top_left)),
100% calc(100% * var(--top_right)),
100% 100%,
0% 100%
);
- Here, by using the clip-path property, with p1 = (0,100% * –top_left ), p2 = (0,100% * –top_right), p3 = (100,100), p4= (0,100) where p1,p2,p3,p4 are 4 points of the shape, to clip the data items into proper shape.
This is an example of a data item in the graph:
Note: The custom variables –top_left and –top_right are important to get the length of the data item in the graph. So, we can apply the same style with different dimensions for different data items.
Example 1: This example describes the basic implementation of the above steps mentioned to create the Area Chart.
HTML
<!DOCTYPE html>
< html >
< head >
< title >Area Chart</ title >
< style >
.area_chart {
width: 700px;
height: 400px;
display: flex;
}
.area_chart>* {
flex-grow: 1;
border: 0.1px solid;
background: rgba(118, 255, 30, .75);
clip-path: polygon(0% calc(100% * var(--top_left)),
100% calc(100% * var(--top_right)),
100% 100%,
0% 100%);
}
</ style >
</ head >
< body >
< h1 style = "color:green" >GeekForGeeks</ h1 >
< h3 >How to create an Area Chart using CSS ?</ h3 >
< div class = "area_chart" >
< div style = "--top_left: 0.9; --top_right: 0.6;" ></ div >
< div style = "--top_left: 0.6; --top_right: 0.4;" ></ div >
< div style = "--top_left: 0.4; --top_right: 0.5;" ></ div >
< div style = "--top_left: 0.5; --top_right: 0.2;" ></ div >
</ div >
</ body >
</ html >
|
Output:
Example 2: This is the more elegant look of the above chart. In this, we are using paragraph tag <p> to represent the data items and also we are adding some space between the data items using justify-content. Adding 20% as width and rounding the data items with border-radius as shown in the output.
HTML
<!DOCTYPE html>
< html >
< head >
< title >Area Chart </ title >
< style >
.area_chart {
width: 700px;
height: 400px;
border-bottom: 6px solid rgba(118, 255, 30, .75);
display: flex;
justify-content: space-between;
}
.area_chart>* {
width: 20%;
border-radius: 50px;
background: rgba(118, 255, 30, .75);
clip-path: polygon(0% calc(100% * var(--top_left)),
100% calc(100% * var(--top_right)),
100% 100%,
0% 100%);
}
p {
margin: 0;
}
</ style >
</ head >
< body >
< h1 style = "color:green" >GeekForGeeks</ h1 >
< h3 >How to create an Area Chart using CSS ?</ h3 >
< div class = "area_chart" >
< p style = "--top_left: 0.9; --top_right: 0.6;" ></ p >
< p style = "--top_left: 0.6; --top_right: 0.4;" ></ p >
< p style = "--top_left: 0.4; --top_right: 0.5;" ></ p >
< p style = "--top_left: 0.5; --top_right: 0.2;" ></ p >
</ div >
</ body >
</ html >
|
Output:
Similar Reads
How to create a Chevron Arrow using CSS ?
In the article, we will see how to make a Chevron Arrow using CSS. A Chevron Arrow is an arrow, often used to indicate direction or to represent navigation elements. Creating a chevron arrow using CSS involves using CSS properties like border and transform to generate the arrow shape. Syntaxtransfor
3 min read
How to create a Pie Chart using HTML & CSS ?
A 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 the pie chart. These charts are very good for displ
2 min read
How to create chart using bootstrap ?
A chart in Bootstrap is a graphical representation for data visualization, in which the data is represented by symbols. The various types of charts like bar charts, line charts, pie charts, donut charts, etc are created with the help of Bootstrap. In other words, we can say that chart is a type of d
3 min read
How To Create a Skill Bar using CSS?
A skill bar is a type of progress bar that visually represents your proficiency in various skills, making it easier for recruiters or customers to understand your expertise. We will learn how to create a skill bar using CSS. ApproachThe HTML structure includes a container div with multiple div eleme
3 min read
How to create and style border using CSS ?
The border property is used to create a border around an element and defines how it should look. There are three properties of the border. border-colorborder-widthborder-style border-style property: This defines how the border should look like. It can be solid, dashed, offset, etc. The following val
4 min read
How to create Animated bars using HTML and CSS?
Dancing bars are one of the classical components that are used in making a good looking website. They are very simple to implement and can be used as a loader or an animation while recording sound. Approach: The approach is to use unordered list to create bars and then animate them using keyframes.
2 min read
Create an Icon Bar using HTML and CSS
This article provides a complete idea of how to create an Icon Bar using HTML and CSS. HTML is used to design the structure, and CSS applies styles to the elements to make the user interface (UI) attractive. To add the Icons, we use the Font Awesome icons CDN link in the head section, and add the ic
2 min read
How to Create Badges using HTML and CSS ?
This article will show you how to create a badge using HTML and CSS. Badges are simple and basic components that are used to display an indicator or count a number. This is quite useful for mail count and alerting purposes, among other things. Badges are identical to labels, with the exception that
2 min read
How to create a Line Chart With CSS ?
The Chart is a pictorial or graphical representation of the data visualization, based on certain conditions There are various types of charts available such as Bar Charts, Line Charts, Pie Charts, etc, that are used to represent important data. In this article, we will see how to create the Line cha
6 min read
How to Create an Area Chart in Seaborn?
In this article, we are going to see how to create an area chart in seaborn using Python. Area Charts are a great way to quickly and easily visualize things to show the average overtime on an area chart. Area charts are different from line graphs. Area charts are primarily used for the summation of
3 min read