Very Simple Responsive Gantt Chart With Pure HTML CSS

Welcome to a tutorial on how to create a Gantt Chart with pure HTML and CSS. Want to include a Gantt Chart in your project? Without using complicated and bloated libraries? Yes, it is possible with the modern CSS grid – Read on for an example!

ⓘ I have included a zip file with all the source code at the start of this tutorial, so you don’t have to copy-paste everything… Or if you just want to dive straight in.

 

 

TABLE OF CONTENTS

Download & Demo CSS Gantt Useful Bits & Links
The End

 

DOWNLOAD & DEMO

Firstly, here is the download link to the example code as promised.

 

QUICK NOTES

If you spot a bug, feel free to comment below. I try to answer short questions too, but it is one person versus the entire world… If you need answers urgently, please check out my list of websites to get help with programming.

 

EXAMPLE CODE DOWNLOAD

Click here to download all the example source code, I have released it under the MIT license, so feel free to build on top of it or use it in your own project.

 

CSS GANTT CHART DEMO

Mon
Tue
Wed
Thur
Fri
Sat
Sun
First
Second
Third

 

 

PURE CSS GANTT CHART

All right, let us now get into the steps of building a simple Gantt chart using HTML and CSS grid.

 

PART 1) GANTT CHART HTML

gantt.html
<div class="gantt">
  <!-- (A) FIRST ROW : DAYS -->
  <div class="head">Mon</div> <div class="head">Tue</div>
  <div class="head">Wed</div> <div class="head">Thur</div>
  <div class="head">Fri</div> <div class="head">Sat</div>
  <div class="head">Sun</div>
 
  <!-- (B) FOLLOWING : TASKS -->
  <div style="background: #ffdddd; grid-row: 2; grid-column: 1 / span 2">
    First
  </div>
  <div style="background: #d6ffd8; grid-row: 3; grid-column: 3 / span 3">
    Second
  </div>
  <div style="background: #e2e5ff; grid-row: 4; grid-column: 5 / span 3">
    Third
  </div>
</div>

Yep, that’s all we need.

  • <div class="gantt"> Container for the Gantt Chart.
  • <div class="head"> The “header cells”. Here, we have Monday to Sunday – A total of 7 cells.
  • <div>TASK</div> Self-explanatory, the individual tasks. Will explain more below.

 

 

PART 2) CONTAINER CSS

gantt.css
/* (A) GANTT CHART CONTAINER */
.gantt {
  /* (A1) GRID LAYOUT - 7 COLUMNS */
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
 
  /* (A2) "TIMELINE" */
  background: repeating-linear-gradient(
   to right, #f2f2f2, #ddd 2px, #fff 2px, #fff 14.25%
  );
}
  • (A1) Captain Obvious to the rescue, set <div class="gantt"> into the grid layout. Since it is Mon-Sun, there are 7 columns in total.
  • (A2) Using a linear-gradient “hack”, we draw the “timelines” in the background.

 

PART 3) HEADER CELLS

gantt.css
/* (B) CELLS */
/* (B1) SHARED CELLS */
.gantt div { padding: 10px; }
 
/* (B2) HEADER CELLS */
.gantt .head {
  text-align: center;
  font-weight: 700;
  color: #fff;
  background: #103a99;
}

Don’t think these need explanation, just some cosmetics for the header cells.

 

 

PART 4) TASK CELLS

gantt.html
<div style="background: #ffdddd; grid-row: 2; grid-column: 1 / span 2">
  First
</div>
<div style="background: #d6ffd8; grid-row: 3; grid-column: 3 / span 3">
  Second
</div>

Lastly, all we need is to insert the tasks themselves. This can be quite confusing if you have zero knowledge of the CSS grid, so I will leave a link below if you want to learn more.

  • grid-row: N This task should be placed at this row in the grid.
  • grid-column: X / span Y This task will start at column X, span across Y cells.

 

USEFUL BITS & LINKS

That’s all for the tutorial, and here is a small section on some extras and links that may be useful to you.

 

IT WORKS, BUT…

Yes, we can totally build a Gantt Chart using pure HTML and CSS only. But as you can see, this is pretty much for simple charts only. It quickly turns into a real pain if you have multiple tasks and a long timeline – Having to manually calculate the rows/columns/span is going to be nasty.

Some form of “automation” with Javascript is still preferred for massive charts – Maybe I will build one in the future.

 

COMPATIBILITY CHECKS

This Gantt Chart will work on all modern “Grade A” browsers.

 

LINKS & REFERENCES

 

THE END

Thank you for reading, and we have come to the end. I hope that it has helped you to better understand, and if you want to share anything with this guide, please feel free to comment below. Good luck and happy coding!

1 thought on “Very Simple Responsive Gantt Chart With Pure HTML CSS”

  1. This is great, and very easy to follow. I’ve been taking a Full Stack Java course for the last 6 months, and I was hoping to add a gantt chart to my project centered around tasks I can CRUD from. I’m still working through this one as I’m having trouble getting my css file linked. Did you ever have a chance to create a javascript file?

Leave a Comment

Your email address will not be published. Required fields are marked *