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:

Let’s add some CSS styling to it:

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.

Let’s add some CSS styling to it:

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.

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:

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.

Here is its CSS:

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:

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:

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

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

Source link

Write A Comment