Create a Gantt Chart with jQuery: A Clear Step-by-Step Guide
A project plan can become hard to follow when tasks overlap, deadlines shift, and nobody can see the full schedule. A plain list may show what needs doing, but it rarely makes dependencies or timing conflicts obvious.
Building a Gantt chart with jQuery can feel like a lot of work, too. You need dates, task bars, layout rules, and a way to keep everything readable as the schedule grows.
But here's the truth: you can create a useful chart with a small amount of HTML, CSS, and jQuery. I’ll walk you through a working example, explain how its date calculations fit together, and show you what to improve before using it for a real project.
How to create a Gantt chart with jQuery
Start with a list of tasks, each with a name, start date, and end date. Then use JavaScript to calculate the project timeline and jQuery to render task bars in the right positions.
The example below displays one column per day. It uses inclusive end dates, so a task scheduled from June 2 through June 4 occupies three days.
1. Add the chart container and load jQuery
Place a container where the chart should appear. Load jQuery before your chart script, or use your existing project’s package setup.
<div class="gantt-scroll">
<div id="gantt" aria-label="Project schedule"></div>
</div>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
The outer element allows horizontal scrolling when the schedule covers many days. That keeps each date column readable instead of squeezing the whole timeline into a narrow space.
2. Style the timeline and task bars
Each chart row has a task name and a timeline area. CSS Grid aligns the rows, while a repeating background creates subtle daily divisions.
<style>
.gantt-scroll {
overflow-x: auto;
border: 1px solid #d9e0e8;
border-radius: 8px;
}
#gantt {
display: grid;
width: max-content;
font: 14px Arial, sans-serif;
}
.gantt-header,
.gantt-row {
display: grid;
min-height: 44px;
border-bottom: 1px solid #e6ebf1;
}
.gantt-header {
background: #f4f7fa;
font-weight: 700;
}
.task-name {
box-sizing: border-box;
padding: 12px;
border-right: 1px solid #d9e0e8;
}
.date-track {
display: grid;
}
.date-cell {
box-sizing: border-box;
width: 36px;
padding-top: 12px;
overflow: hidden;
border-right: 1px solid #e6ebf1;
text-align: center;
font-size: 11px;
}
.timeline {
position: relative;
min-height: 44px;
background-image: linear-gradient(
to right,
transparent 35px,
#e6ebf1 35px,
#e6ebf1 36px
);
background-size: 36px 100%;
}
.task-bar {
position: absolute;
top: 10px;
height: 24px;
box-sizing: border-box;
overflow: hidden;
padding: 4px 7px;
border-radius: 5px;
background: #3478c8;
color: #fff;
white-space: nowrap;
font-size: 12px;
}
</style>
The fixed 36-pixel day width makes the date math predictable. You can adjust that value later, but remember to update both the CSS and the JavaScript calculations.
3. Define tasks and calculate the date range
Keep dates in the ISO format YYYY-MM-DD. The chart needs the earliest task start and latest task end to determine how many day columns it should render.
<script>
$(function () {
const tasks = [
{ name: "Plan requirements", start: "2025-06-02", end: "2025-06-04" },
{ name: "Design interface", start: "2025-06-04", end: "2025-06-09" },
{ name: "Build prototype", start: "2025-06-07", end: "2025-06-13" },
{ name: "Review and test", start: "2025-06-12", end: "2025-06-16" }
];
const dayMs = 24 * 60 * 60 * 1000;
const columnWidth = 36;
const labelWidth = 180;
function parseUTC(value) {
const parts = value.split("-").map(Number);
return Date.UTC(parts[0], parts[1] - 1, parts[2]);
}
function formatShortDate(timestamp) {
const date = new Date(timestamp);
return (date.getUTCMonth() + 1) + "/" + date.getUTCDate();
}
const startDates = tasks.map(function (task) {
return parseUTC(task.start);
});
const endDates = tasks.map(function (task) {
return parseUTC(task.end);
});
const projectStart = Math.min.apply(null, startDates);
const projectEnd = Math.max.apply(null, endDates);
const dayCount = Math.round((projectEnd - projectStart) / dayMs) + 1;
const columns = labelWidth + "px repeat(" + dayCount + ", " + columnWidth + "px)";
const $gantt = $("#gantt");
$gantt.css("grid-template-columns", columns);
const $header = $("<div>")
.addClass("gantt-header")
.css("grid-template-columns", columns);
const $taskHeading = $("<div>")
.addClass("task-name")
.text("Task");
const $dateTrack = $("<div>")
.addClass("date-track")
.css("grid-template-columns", "repeat(" + dayCount + ", " + columnWidth + "px)");
for (let day = 0; day < dayCount; day++) {
const currentDate = projectStart + day * dayMs;
$("<div>")
.addClass("date-cell")
.text(formatShortDate(currentDate))
.appendTo($dateTrack);
}
$header.append($taskHeading, $dateTrack);
$gantt.append($header);
tasks.forEach(function (task) {
const taskStart = parseUTC(task.start);
const taskEnd = parseUTC(task.end);
const startOffset = Math.round((taskStart - projectStart) / dayMs);
const duration = Math.round((taskEnd - taskStart) / dayMs) + 1;
const $row = $("<div>")
.addClass("gantt-row")
.css("grid-template-columns", columns);
const $name = $("<div>")
.addClass("task-name")
.text(task.name);
const $timeline = $("<div>")
.addClass("timeline")
.css("grid-column", "2 / -1");
const $bar = $("<div>")
.addClass("task-bar")
.text(task.name)
.attr("title", task.name + ": " + task.start + " to " + task.end)
.css({
left: startOffset * columnWidth + "px",
width: duration * columnWidth - 4 + "px"
});
$timeline.append($bar);
$row.append($name, $timeline);
$gantt.append($row);
});
});
</script>
UTC timestamps help avoid shifts caused by local daylight-saving changes. The chart positions each bar by counting days from the project’s first date, then multiplies that count by the column width.
4. Check the chart in a browser
Open the page and confirm that the headings, task labels, and bars appear. The “Design interface” task starts on June 4, so its bar should begin in the fourth displayed date column.
Look closely at the end dates. Because this example treats them as inclusive, “Plan requirements” spans June 2, 3, and 4. If your project treats end dates as exclusive, remove the extra day from the duration calculation.
5. Add input checks before using real schedules
The demo assumes every task has valid dates and a start date no later than its end date. Add validation before rendering so an incorrect entry does not create a negative-width bar or a misleading schedule.
- Confirm each date matches the expected ISO format.
- Check that the end date is the same as or later than the start date.
- Handle an empty task list before calling minimum or maximum date calculations.
- Set a practical maximum timeline range for very long projects.
How the date and layout calculations work
A Gantt chart maps calendar time onto horizontal space. In this example, one day equals 36 pixels, so a task starting five days after the project begins gets a 180-pixel offset.
The formula is straightforward: start offset × column width determines the bar’s left position. The inclusive duration is end date − start date + 1, multiplied by the same column width.
Use consistent date parsing
JavaScript date handling can behave differently when strings are interpreted in local time. Parsing each date into a UTC timestamp keeps the day calculations consistent across time zones.
For example, June 2 to June 4 has a two-day difference between timestamps. Adding one creates a three-day visual duration, matching an inclusive schedule.
Keep chart width under control
A 36-pixel column works for short plans, but a year-long daily schedule becomes very wide. Horizontal scrolling keeps the chart usable, while a weekly or monthly scale can help with longer projects.
For a weekly view, calculate offsets in weeks and change the header labels to week starts. Keep the date granularity consistent across task positions, widths, and headings.
Ways to make the chart more useful
A basic timeline helps people see dates, but small interface improvements make it easier to interpret. Choose enhancements that answer real project questions instead of adding decoration for its own sake.
Show milestones and task status
A milestone can appear as a narrow marker instead of a multi-day bar. A status color can distinguish planned, active, delayed, and complete work, provided you also include a text label or legend.
For example, a green bar labeled “Complete” communicates more clearly than color alone. That matters for readers with color-vision differences and for printed schedules.
Make overlapping work easy to spot
Overlapping bars can reveal parallel work, but they can also hide conflicts. Add dependency lines or warnings when a task starts before its predecessor finishes.
Consider two tasks that both require the same designer. Their date bars may overlap, even though the person cannot complete both simultaneously. A chart can show the clash, but it needs resource information to explain it.
Support keyboard and screen-reader access
Provide a clear chart label, meaningful task names, and text descriptions for status. Keep essential information available outside the visual timeline, too.
A screen-reader-friendly task list can include each task’s start date, end date, and status. This gives people another way to understand the schedule without relying on bar position.
Testing and maintaining a jQuery Gantt chart
Test the chart with realistic cases, not just four neatly ordered tasks. A schedule with a single task, a long gap, or an unusually long duration can expose layout problems quickly.
Test edge cases
Try tasks that begin and end on the same day, tasks that overlap, and tasks with dates spanning a year boundary. Confirm that each bar begins and ends in the expected columns.
Also test invalid dates and an empty task list. If the chart is updated dynamically, check whether old rows are cleared before new ones are rendered.
Consider performance as schedules grow
Rendering one element for every date and task is manageable for small plans. Hundreds of tasks across several years can create a large page that takes longer to draw and navigate.
For larger schedules, consider grouping tasks, rendering only the visible time range, or changing from daily columns to weekly or monthly intervals. Measure the experience in the browsers your team uses.
When a project management platform may fit better
A custom jQuery chart makes sense when you need a focused visual schedule in an existing site or application. It gives you control over the display, but you also own updates, validation, access rules, and ongoing maintenance.
If a project needs task ownership, workflow, reporting, and shared knowledge alongside its schedule, a project management platform may reduce the amount of custom work. ONES.com offers project management and knowledge management as a unified platform, with ONES Project and ONES Wiki sold separately.
ONES.com solution for project planning beyond a custom chart

Value proposition
ONES.com brings project management and knowledge management together for teams that need more than a visual timeline. ONES Project is a Jira alternative for managing project work, while ONES Wiki is a Confluence alternative for organizing team knowledge.
You can choose the product that fits your needs, with cloud and self-hosted deployment options. This can help teams move from maintaining a custom chart to managing project work in a shared environment.
Core capabilities
- Pain: A custom timeline shows dates but offers limited workflow support. ONES capability: ONES Project supports Jira-compatible workflows. Result: Teams can structure work around familiar processes.
- Pain: A chart requires extra coding to capture project-specific fields. ONES capability: Teams can configure custom workflows and fields. Result: Project information can better reflect the way work moves.
- Pain: A simple timeline does not cover sprint planning. ONES capability: ONES Project includes sprint management. Result: Teams can coordinate work across iterative delivery cycles.
- Pain: Status updates can become repetitive. ONES capability: Automation can handle routine project actions. Result: Teams can reduce manual steps in recurring processes.
- Pain: A visual schedule may not provide enough progress visibility. ONES capability: Built-in reporting supports project tracking. Result: Teams can review progress without building every report themselves.
- Pain: Separate tools can make planning and team knowledge harder to connect. ONES capability: ONES.com includes project management and knowledge management products. Result: Teams can select a coordinated setup for work and shared knowledge.
- Pain: A hosted service may not suit every environment. ONES capability: Deployment options include Cloud, On-Premise, Private Cloud, and Air-gapped. Result: Teams can choose an environment that fits their operating requirements.
- Pain: Teams may depend on add-ons to cover basic project needs. ONES capability: Native project capabilities include workflows, fields, reporting, sprints, and automation. Result: Teams may be able to reduce plugin dependence.
Application scenarios
Growing software team: A team starts with a custom Gantt chart but later needs sprint planning, configurable workflows, and project reports. ONES Project can support those project management needs without requiring the team to maintain every feature in custom code.
Restricted operating environment: A team needs project management within a controlled network. ONES.com offers self-hosted options, including On-Premise, Private Cloud, and Air-gapped deployments, with feature parity between cloud and self-hosted versions.
A hand-built jQuery chart remains useful for a focused display or a learning project. ONES.com is worth considering when the challenge grows into managing the wider project workflow and team knowledge.
Common challenges when building a chart with jQuery
Bars appear one day too short
Problem: The calculation treats the end date as exclusive, while the project team expects it to count as a working day. Solution: Add one day to the duration for inclusive schedules, then confirm the convention with the people using the chart.
Dates shift across time zones
Problem: Local date parsing can introduce unexpected offsets, especially near daylight-saving changes. Solution: Parse date components consistently in UTC, as the example does, and test the result in more than one time zone.
The chart becomes too wide
Problem: A daily timeline across months or years may require extensive scrolling. Solution: Use a weekly or monthly scale for long-range planning, or limit the visible date range to the period people need to review.
Task labels or bars do not fit
Problem: Long task names can be clipped inside narrow bars. Solution: Keep task names in the label column, use the bar’s title for a short hover detail, and avoid putting essential information only inside the bar.
FAQs
Can I create a Gantt chart using jQuery alone?
jQuery can create and update the page elements, but the complete chart also needs HTML and CSS. HTML provides the container, CSS handles layout and styling, and JavaScript calculates task positions. jQuery makes it convenient to build and insert the chart elements. The example combines all three rather than relying on jQuery as a standalone charting engine.
Does this example support task dependencies?
No. The example positions tasks by their start and end dates, but it does not store dependency relationships or draw connectors. You could add a predecessor field to each task, validate that dependent tasks follow the correct order, and draw dependency lines. For complex dependency behavior, plan and test that feature separately from basic bar placement.
How can I display weekends differently?
Track the date represented by each column and apply a weekend class when its day falls on Saturday or Sunday. Then use CSS to give those columns a different background. For a working-day schedule, you’ll also need to calculate durations and offsets while skipping weekends, rather than simply counting calendar days.
Is a custom jQuery Gantt chart suitable for a large project?
It can work for a modest schedule, especially when the chart serves a specific display need. As task counts and timeline lengths grow, rendering and navigation become more demanding. Features such as permissions, dependencies, reporting, and ongoing maintenance also require additional development. Test with a realistic project before deciding whether a custom chart still fits.
Conclusion
You can create a practical Gantt chart with jQuery by defining tasks, calculating a consistent date range, and positioning bars on a CSS grid. The example gives you a starting point for visualizing task dates and overlap.
But here's the truth: a small chart is only one part of project planning. Add date validation, accessible labels, and a suitable time scale before relying on it for day-to-day coordination.
If your needs grow beyond a custom timeline, consider whether a project management platform fits the wider workflow. The right approach is the one that makes your schedule clear, maintainable, and useful to the people doing the work.