DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Create Column Charts With JavaScript
  • Subtitles: The Good, the Bad, and the Resource-Heavy
  • Loader Animations Using Anime.js
  • Next.js Theming: CSS Variables for Adaptive Data Visualization

Trending

  • AI, ML, and Data Science: Shaping the Future of Automation
  • Agile and Quality Engineering: A Holistic Perspective
  • Apache Doris vs Elasticsearch: An In-Depth Comparative Analysis
  • A Guide to Developing Large Language Models Part 1: Pretraining
  1. DZone
  2. Coding
  3. Languages
  4. How to Create a Simple Gantt Chart Using CSS Grid

How to Create a Simple Gantt Chart Using CSS Grid

In this article, we discuss how to create a simple Gantt chart using CSS Grid to better manage your project workloads.

By 
Alfrick Opidi user avatar
Alfrick Opidi
·
Updated Feb. 13, 20 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
19.3K Views

Join the DZone community and get the full member experience.

Join For Free

A Gantt chart is a handy type of bar chart that is used in project management for showcasing a schedule of tasks. This chart visualizes project activities as cascading horizontal bars, with width depicting the project’s duration. 

As a front-end web designer or developer, you can make use of Gantt charts to manage projects and enhance the productivity within your team.

In this article, I’m going to show you how to create a simple Gantt chart using the CSS Grid Layout system—no external libraries or other fluff, just pure CSS.

You may also like: Redesigning a Website Using CSS Grid and Flexbox.

You can reference this tutorial to understand how to use the layout system for applying CSS rules.

The chart will show a typical software development life cycle process, from January to December. 

Here is a screenshot of how the Gantt chart will look at the end of this tutorial:

Gantt Chart

Let’s get started!

Step 1: Create a Container div

Let’s start by creating a container div element for the Gantt Chart:

HTML
 




xxxxxxxxxx
1


 
1
<div class="container">
2
  
3
</div>



Let’s add some CSS styling to it:

CSS
 




xxxxxxxxxx
1


 
1
.container {
2
  max-width: 1200px;     
3
  min-width: 650px;     
4
  margin: 0 auto;     
5
  padding: 50px;
6
}



Step 2: Create a Chart div

Let’s create a div inside the overarching container and name it chart. This is where all the remaining actions are going to take place.

HTML
 




xxxxxxxxxx
1


 
1
<div class="chart"> 
2
  
3
</div>



Let’s add some CSS styling to it:

CSS
 




xxxxxxxxxx
1


 
1
.chart {   
2
  display: grid;     
3
  border: 2px solid #000;      
4
  position: relative;      
5
  overflow: hidden; 
6
} 



Notice that I’ve set the display property of the class to grid. Consequently, all its direct children will automatically become grid items.

Step 3: Create the Chart’s Rows

Let’s start by creating the first row, which will be the heading of the Gantt chart.

HTML
 




x


 
1
<div class="chart-row chart-period">
2
<div class="chart-row-item">
3
    </div><span>January</span><span>February</span>span>March</span>
4
    <span>April</span><span>May</span><span>June</span><span>July</span>
5
    <span>August</span><span>September</span><span>October</span>
6
    <span>November</span><span>December</span>
7
</div>



Notice that I’ve provided 12 span elements that will transverse the entire row, showing the months of the project’s duration — from January to December.

Here is its CSS:

CSS
 




xxxxxxxxxx
1


 
1
.chart-row {  
2
    display: grid; 
3
    grid-template-columns: 50px 1fr; 
4
    background-color: #DCDCDC;
5
}



CSS
 




xxxxxxxxxx
1
15


 
1
.chart-period { 
2
    color:  #fff;  
3
    background-color:  #708090 !important;  
4
    border-bottom: 2px solid #000;  
5
    grid-template-columns: 50px repeat(12, 1fr);
6

          
7
}
8

          
9
.chart-period > span {
10
    text-align: center;  
11
    font-size: 13px;  
12
    align-self: center;  
13
    font-weight: bold;  
14
    padding: 15px 0;   
15
}



Notice that I used the grid-template-columns property to specify the width and the number of columns in the grid layout.

Let’s see how it looks in a browser, so far:

browser view

Next, let’s add lines that will run throughout the chart in a box-like style, which helps showcase the duration of each project. 

I also used 12 span elements for creating the lines.

CSS
 




xxxxxxxxxx
1


 
1
<div class="chart-row chart-lines"> 
2
    <span></span><span></span><span></span>
3
    <span></span><span></span><span></span>
4
    <span></span><span></span><span></span>
5
    <span></span><span></span>  <span></span>    
6
</div>



Here is its CSS:

CSS
 




xxxxxxxxxx
1
10


 
1
.chart-lines { 
2
    position: absolute;  
3
    height: 100%;  
4
    width: 100%;  
5
    background-color: transparent;  
6
    grid-template-columns: 50px repeat(12, 1fr);}
7

          
8
.chart-lines > span {  
9
    display: block;  border-right: 1px solid rgba(0, 0, 0, 0.3);
10
}



Let’s see the output in a browser:

browser view

Step 4: Add Entry Items

Finally, let’s add the items that illustrate a year-long process of creating some software.

For example, here is how I added the first entry item:

CSS
 




xxxxxxxxxx
1


 
1
<div class="chart-row">  
2
    <div class="chart-row-item">1</div> 
3
    <ul class="chart-row-bars">    
4
        <li class="chart-li-one">Planning</li>
5
    </ul>
6
</div>



Let me describe what is happening in the code above:

  • First, the encompassing div element has a class of chart-row, which I illustrated earlier.
  •  
  • The div with a class of chart-row-item is used for numbering the entry items on the Gantt chart. Here is its CSS:

  • To show tasks on the Gantt chart, I created an unordered list and styled it to display a horizontal bar, with its length showing the duration of the task. 

Here is the CSS styling for the chart-row-bars class:

CSS
 




xxxxxxxxxx
1


 
1
.chart-row-bars { 
2
    list-style: none; 
3
    display: grid;  padding: 15px 0;  
4
    margin: 0;  
5
    grid-template-columns: repeat(12, 1fr); 
6
    grid-gap: 10px 0;  
7
    border-bottom: 1px solid #000;
8
}


  • The entry item is defined in the li tag. Here is its CSS styling:
CSS
 




xxxxxxxxxx
1
16


 
1
li {  
2
    font-weight: 450;  
3
    text-align: left;  
4
    font-size: 15px;  min-height: 15px;  
5
    background-color: #708090;  
6
    padding: 5px 15px;  color: #fff;  
7
    overflow: hidden;  
8
    position: relative;  
9
    cursor: pointer;  
10
    border-radius: 15px;
11
 } 
12
 
13
 ul .chart-li-one { 
14
    grid-column: 1/2;  
15
        background-color: #588BAE;
16
 }



Notice that I’ve used the grid-column property to specify the duration of the project. 

For example, a property of grid-column: 3/9; like the “Development” entry, spans a task across the grid from March to August.

Here is how the first entry item looks in a browser:

planning in browser

I added the other entries on the chart following the same process as the first entry.

Ultimately, it resulted in a nice-looking Gantt chart, just like the image I showed earlier. 

Wrapping Up

That’s it! You can view the entire code for this tutorial on CodePen:

As you’ve seen, creating a Gantt chart using CSS Grid is not complicated. With this type of chart, you can manage your web development projects effectively and ensure that everyone is on track toward accomplishing the stipulated objectives.

Furthermore, Gantt charts can also be used in other industries to manage projects. For example, if you are selling composting toilets, you can use Gantt charts to showcase the number of sales made over a period of time. 

Of course, I’ve just scratched the surface about the things you can achieve with Gantt charts. 

There are several other tweaks you can make to Gantt charts to suit your specific requirements and project goals. 

For example, you can use them to show the relationship between various tasks and how the completion of one relies on another, show how resources can be allocated for the success of projects, and show clear project requirements that ensure everyone is on the same page.

Do you have any questions or comments?

Please get in touch  and I’ll do my best to respond.

This article first appeared on freeCodeCamp.

Further Reading

  • Get Started With a Web Components Grid in 5 Minutes.
  • Responsive Web Design.

CSS Chart

Published at DZone with permission of Alfrick Opidi. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Create Column Charts With JavaScript
  • Subtitles: The Good, the Bad, and the Resource-Heavy
  • Loader Animations Using Anime.js
  • Next.js Theming: CSS Variables for Adaptive Data Visualization

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!