<gantt-chart>
HTML-first Gantt chart using native table, progress, and time elements with progressive enhancement to an interactive timeline.
Overview
A web component that progressively enhances a semantic <table> into an interactive Gantt timeline. Without JavaScript, users see a fully readable data table with native <progress> bars and <time> elements. With JavaScript, the component renders a visual timeline with positioned bars, swim lane groups, milestones, progress fill, and a today marker.
<gantt-chart title="Q2 Roadmap" show-today show-progress> <table> <thead> <tr><th>Task</th><th>Start</th><th>End</th><th>Progress</th></tr> </thead> <tbody> <tr data-task-id="design" data-group="Design" data-status="in-progress"> <td>Design system</td> <td><time datetime="2026-04-01">Apr 1</time></td> <td><time datetime="2026-04-15">Apr 15</time></td> <td><progress value="75" max="100">75%</progress></td> </tr> <tr data-task-id="api" data-group="Engineering" data-depends="design"> <td>API development</td> <td><time datetime="2026-04-10">Apr 10</time></td> <td><time datetime="2026-04-25">Apr 25</time></td> <td><progress value="30" max="100">30%</progress></td> </tr> <tr data-task-id="launch" data-depends="api" data-milestone> <td>Launch</td> <td><time datetime="2026-05-01">May 1</time></td> <td><time datetime="2026-05-01">May 1</time></td> <td><progress value="0" max="100">0%</progress></td> </tr> </tbody> </table></gantt-chart>
Attributes
| Attribute | Values | Default | Description |
|---|---|---|---|
title | string | — | Chart heading (a src JSON "title" sets it) |
src | string | — | URL of JSON task data ({ title?, tasks: [...] }). Fetched once on connect or when the attribute changes; the fetched tasks replace the child table. A newer value aborts an older in-flight request. Skipped on connect when .tasks was already assigned, and an in-flight request is aborted when .tasks is assigned (.tasks takes precedence) |
view | "auto", "day", "week", "month", "quarter" | "auto" | Timeline granularity. auto picks day (≤ 3 weeks), week (≤ 90 days), month (≤ 1 year) or quarter |
show-today | boolean | — | Show vertical today marker line |
show-progress | boolean | — | Show progress fill inside bars |
show-dependencies | boolean | — | Draw dependency arrows between tasks (row positions are measured, so compact and grouped charts line up) |
compact | boolean | — | Reduced row height and spacing |
Task Row Attributes
Each <tr> in the table body can carry these data attributes to configure the corresponding task bar.
| Attribute | On | Values | Description |
|---|---|---|---|
data-task-id | tr | string | Unique task identifier (used by data-depends) |
data-group | tr | string | Swim lane group; with two or more groups each gets a header row |
data-depends | tr | string | Comma-separated task IDs this task depends on (drawn with show-dependencies) |
data-status | tr | "not-started", "in-progress", "done", "blocked" | Task status: shown as text in the task list and in the bar's accessible name; also tints the bar |
data-assignee | tr | string | Assignee name (included in the bar's accessible name) |
data-milestone | tr | boolean | Render a diamond marker at the start date instead of a duration bar |
data-color | tr | string | Custom bar colour (any CSS colour) |
data-story-ids | tr | string | Comma-separated linked user-story IDs (exposed as task.storyIds) |
data-item-ids | tr | string | Comma-separated linked work-item IDs (exposed as task.itemIds) |
How It Works
The component reads task data from the semantic table structure:
- Task name — from the first
<td>text - Start/end dates — from
<time datetime="YYYY-MM-DD">elements - Progress — from
<progress value="..." max="..."> - Metadata — from
data-*attributes on the<tr>
Dates are calendar days in the viewer's local time zone: 2026-04-01 is shown as April 1 everywhere (it is not read as UTC midnight). Positions are measured in whole days, so daylight-saving changes don't shift bars. Each bar is positioned at left: (taskStart - rangeStart) / rangeDays * 100% with width: (taskEnd - taskStart) / rangeDays * 100%; the range runs from the earliest start to the latest end. The timeline granularity auto-adjusts based on the date range, or can be set explicitly via the view attribute; month and quarter ticks fall on the 1st of the month or quarter.
Data Mode
Load task data from JSON via the src attribute. It is fetched once when the element connects (whether src was set before or after) and again only when src changes; moving the element in the DOM does not refetch. The loaded tasks replace any child table, and the component generates a visually hidden table from them for screen readers. A "title" in the JSON sets the title attribute. A newer src aborts an older in-flight request.
Precedence: .tasks wins over src. If .tasks is assigned before the element connects, the initial src is not fetched, and assigning .tasks while a src request is in flight aborts it. Changing src afterwards loads that URL (the most recent source wins). gantt-chart:ready fires once per element; later src loads fire gantt-chart:tasks-changed with source: 'src'.
{ "title": "Q2 Roadmap", "tasks": [ { "id": "design", "name": "Design system", "start": "2026-04-01", "end": "2026-04-15", "progress": 75, "group": "Design", "status": "in-progress" }, { "id": "launch", "name": "Launch", "start": "2026-05-01", "end": "2026-05-01", "milestone": true, "depends": ["design"] } ]}
Events
| Event | Detail | Description |
|---|---|---|
gantt-chart:upgraded | — | Once per connect, in a microtask after setup; a safe signal for the first .tasks assignment (fires for an empty chart too) |
gantt-chart:ready | { taskCount, dateRange: { start, end } } | Once per element: after the first connect render that has tasks (table or .tasks), or else after the first src load. Not re-fired on reconnect or by later src loads (those fire tasks-changed with source 'src'). dateRange values are YYYY-MM-DD |
gantt-chart:task-click | { task } | When a bar or milestone is clicked or activated with Enter/Space |
gantt-chart:tasks-changed | { tasks, source: 'property' | 'src' } | After .tasks is assigned (source 'property') or src data loads (source 'src'), with the normalized tasks |
Property API (JS-first)
For reactive frameworks, assign .tasks directly instead of templating the source <table>. Each task is a plain object; start/end accept YYYY-MM-DD strings, Dates or timestamps. Tasks without a valid start are dropped.
| Property | Type | Description |
|---|---|---|
.tasks | Task[] | Setter replaces the chart contents and re-renders, and regenerates the visually hidden table from the new tasks (the authored table is replaced). Assigned tasks survive moving the element in the DOM. Reading returns the normalized array: start/end are local-midnight timestamps, progress is 0–1, depends/storyIds/itemIds are arrays. |
const g = document.querySelector('gantt-chart'); await new Promise(r => g.addEventListener('gantt-chart:upgraded', r, { once: true })); g.tasks = [ { id: 'T1', name: 'Design', start: '2026-04-01', end: '2026-04-15', progress: 0.6 }, { id: 'T2', name: 'Build', start: '2026-04-10', end: '2026-04-25', depends: ['T1'] }, { id: 'T3', name: 'Release', start: '2026-04-30', end: '2026-04-30', milestone: true },]; effect(() => { g.tasks = sprintTasks.get(); }); g.addEventListener('gantt-chart:tasks-changed', (e) => { if (e.detail.source !== 'property') syncStore(e.detail.tasks);});
An empty <gantt-chart> (no table, no src) still upgrades and fires gantt-chart:upgraded, so the JS-first pattern above works. A .tasks value assigned before the element is defined is picked up on upgrade.
See the Data API concepts guide for the dual-mode contract.
CSS Custom Properties
| Variable | Default | Description |
|---|---|---|
--gc-task-width | 180px | Left panel (task names) width |
--gc-row-height | 36px | Row height for tasks and bars (28px with compact). Dependency arrows follow any value. |
--gc-bar-color | var(--color-interactive) | Per-bar color override |
Accessibility
- The task table stays in the DOM (visually hidden) so screen readers get full table semantics with
<th>,<time>, and<progress>. For.tasksandsrcdata the component generates that table from the current tasks. - Each bar and milestone is a focusable
role="button"whose accessible name gives the task name, dates, status, progress and assignee (e.g. “API development: Apr 10, 2026 to May 1, 2026, status: in progress, 40% complete”). Enter or Space activates it and firesgantt-chart:task-click. - Status is shown as text in the task list, not by bar colour alone.
- An
aria-live="polite"region announces task selection. - Dependency arrows are decorative (
aria-hidden); dependencies are not announced. - Attribute-driven re-renders crossfade with a View Transition, skipped under
prefers-reduced-motion: reduce; bar hover transitions are disabled there too. - Print styles show the table and hide the visual chart
Related
<kanban-board>— Track tasks as draggable cards in columns<impact-effort>— Prioritize tasks on impact vs effort<user-story>— Story cards used as kanban items<review-surface>— Annotate the chart with review pins- vb-project-planning — the whole package:
import '@profpowell/vb-project-planning'registers every component