Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Gantt for React

Plan features as bars on a timeline: drag one to reschedule it, pull an edge to change its dates. For React with Base UI, for roadmaps and sprints.

On this page9 sections

A Gantt chart lays work out as bars on a timeline, one row per feature, beside a list that names each row and says how long it runs. Reach for it when the dates are the point: what runs when, what overlaps, what slips past a milestone.

Bars move by drag, by their edges or by the arrow keys, and the dates stay in your state. For work that moves between stages rather than dates, use a Kanban board, and for one day picked from a month, a Calendar.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Gantt anatomy: provider, sidebar, sidebar item, header, feature item, today

Usage

import { useState } from "react";
import {
  type GanttFeature, GanttFeatureItem, GanttFeatureList,
  GanttFeatureListGroup, GanttHeader, GanttProvider, GanttSidebar,
  GanttSidebarGroup, GanttSidebarItem, GanttTimeline, GanttToday,
} from "@/components/ui/gantt";

The bars draw the dates you hold in state. onMove reports each drag or key press with the feature's id and its new dates, and move writes them back.

const status = { color: "var(--primary)", id: "active", name: "In progress" };

const roadmap: GanttFeature[] = [
  {
    endAt: new Date(2026, 10, 20),
    id: "components",
    name: "Component library",
    startAt: new Date(2026, 10, 2),
    status,
  },
  {
    endAt: new Date(2026, 11, 11),
    id: "docs",
    name: "Documentation",
    startAt: new Date(2026, 10, 16),
    status,
  },
];

const Roadmap = () => {
  const [features, setFeatures] = useState(roadmap);
  const move = (id: string, startAt: Date, endAt: Date) => {
    setFeatures((current) =>
      current.map((feature) =>
        feature.id === id ? { ...feature, endAt, startAt } : feature
      )
    );
  };

  return (
    <GanttProvider className="h-96" range="monthly">
      <GanttSidebar>
        <GanttSidebarGroup name="Roadmap">
          {features.map((feature) => (
            <GanttSidebarItem feature={feature} key={feature.id} />
          ))}
        </GanttSidebarGroup>
      </GanttSidebar>
      <GanttTimeline>
        <GanttHeader />
        <GanttFeatureList>
          <GanttFeatureListGroup>
            {features.map((feature) => (
              <GanttFeatureItem
                endAt={feature.endAt}
                id={feature.id}
                key={feature.id}
                name={feature.name}
                onMove={move}
                startAt={feature.startAt}
              />
            ))}
          </GanttFeatureListGroup>
        </GanttFeatureList>
        <GanttToday />
      </GanttTimeline>
    </GanttProvider>
  );
};

Accessibility

A bar that can move is a button named after its feature, with its dates in words after the name, such as Mar 3, 2026 to Apr 2, 2026, and a hidden line that explains the keys describes it. A polite status line reads out the new dates after each move. A bar with no move handler reads the same but is plain text, out of the tab order, since pressing it would do nothing. The sidebar rows are buttons that scroll the chart to their bar. The header and the column grid are hidden from assistive tech, and the dashed add box is out of the tab order, so give keyboard users an add button of their own.

Tab
Moves focus through the sidebar rows, the bars that can move, the marker remove buttons and the add-marker button, in the order they're written.
Enter
On a sidebar row, scrolls the chart to that feature's bar. On a marker's remove button, calls onRemove. On the add-marker button, hands the day it shows to onCreateMarker.
Space
On a sidebar row, scrolls the chart to that feature's bar. On a marker's remove button, calls onRemove. On the add-marker button, hands the day it shows to onCreateMarker.
Arrow Right
On a bar that can move, moves it a day later in the daily range, or a week in the other two. On the add-marker button, moves its day the same way. In a right-to-left layout, it moves earlier.
Arrow Left
On a bar that can move, moves it a day earlier in the daily range, or a week in the other two. On the add-marker button, moves its day the same way. In a right-to-left layout, it moves later.
Shift+Arrow Right
On a bar that can move, moves only its end, the way ArrowRight moves the whole bar, and never past its start.
Shift+Arrow Left
On a bar that can move, moves only its end, the way ArrowLeft moves the whole bar, and never past its start.
Alt+Shift+Arrow Right
On a bar that can move, moves only its start, the way ArrowRight moves the whole bar, and never past its end. On a Mac, Alt is Option.
Alt+Shift+Arrow Left
On a bar that can move, moves only its start, the way ArrowLeft moves the whole bar, and never past its end.
Escape
While a bar or one of its edges is being dragged, cancels the drag and leaves the dates as they were, wherever focus is.

Demos

Ranges and zoom

Four platform features with Daily, Monthly and Quarterly buttons that switch range, and zoom buttons that change zoom by 25, from 50 to 200. A daily column is a day with its weekday and weekends shaded, a monthly one is a month under its year, and a quarterly one is a month under its quarter. After each change the chart scrolls back to today.

Preview width

Groups

A sprint in the daily range, eight tasks in three groups: Design, Build and Ship. Each GanttSidebarGroup has a GanttFeatureListGroup in the same order, and the two line up row for row, with the group's name on the row above its items. Keep the same items in both lists, in the same order, or the rows drift apart.

Preview width

Status colors

A platform roadmap whose bars start with a dot in their status color, the same dot the sidebar rows show, so Done, In progress, At risk and Planned read at a glance. Each GanttFeatureItem holds its own content in place of its label: the dot, the name kept sticky so it stays in view, and the status in hidden text for screen readers. The bars still move.

Preview width

Markers

Design review and Code freeze stand on their days as GanttMarker lines, each label showing its date on hover and a remove button from onRemove. GanttCreateMarkerTrigger puts a button in the header that follows the pointer, or starts on today from the keyboard, and onCreateMarker receives its day. These bars have no onMove, so they show the plan and stay put.

Preview width

Add feature

onAddItem on GanttProvider turns an empty spot of the timeline into a dashed box under the pointer, and a click calls it with that day, which here adds a two-week feature. The box is a pointer's shortcut and stays out of the tab order, so the Add feature today button above the chart does the same for keyboard users.

Preview width

FAQ

What do the daily, monthly and quarterly ranges change in a Gantt chart?

range on GanttProvider sets what a column is: a day in daily, a month under its year in monthly, and a month under its quarter in quarterly. Bars still start and end on whole days in every range, placed inside a month by how far into it they fall.

The timeline covers last year, this year and next, and opens scrolled to today. The arrow keys move a bar a day in the daily range and a week in the other two, and the Ranges and zoom demo switches between all three.

How do I keep the new dates after someone drags a Gantt bar?

Pass onMove to GanttFeatureItem and save what it receives, the feature's id and its new start and end dates, in your state.

The bar draws the dates you pass, so without that update it snaps back where it was. With no handler at all, the bar can't be dragged or moved by key. Dates snap to whole days, and endAt is the last day the feature runs, included.

Can people move a Gantt bar without a mouse?

Yes, once the bar has a move handler, which makes it a button in the tab order. The arrow keys move it a day in the daily range or a week in the others. Shift with an arrow moves only its end, and Alt with Shift only its start.

A polite status line reads out the new dates after each move, and the bar's own name includes its dates. In a right-to-left layout the arrows follow the timeline, so ArrowLeft is later.

How do I make the Gantt columns wider, or the sidebar narrower?

Set zoom on GanttProvider, a percentage of each column's width, 100 by default: 50 halves the columns and 200 doubles them. At 100, a daily column is 50 pixels wide, a monthly one 150 and a quarterly one 100.

The sidebar has its own width. Set the --gantt-sidebar-width variable on the provider, 16rem by default, and the sidebar never takes more than 40 percent of the chart.

How do I add milestones to a Gantt timeline?

Render a GanttMarker inside GanttTimeline for each milestone, with an id, a date and a label, and pass onRemove to give its label a remove button. GanttToday is the same kind of line for today, in the primary color.

To let people place new ones, add GanttCreateMarkerTrigger. Its button follows the pointer across the header, or starts on today from the keyboard, and onCreateMarker receives the chosen day, as the Markers demo shows. Keep the markers in your own state.

Why does the Gantt timeline appear only after the page loads in React?

The chart reads today's date in the browser once it has mounted, and draws nothing dated before then. A server and a browser in different time zones can disagree about the day, and waiting for the browser keeps them from rendering two different charts.

The sidebar renders right away. Give GanttProvider a height, such as h-96, so the page doesn't move when the timeline arrives.

How do I change the color of a Gantt bar?

Bars use the card colors, and a feature's status color shows only as the dot in its sidebar row. A class on GanttFeatureItem lands on the row the bar sits in, not on the bar itself.

Reach the bar from that class through its data-slot: [&_[data-slot=gantt-feature-item-card]]:bg-primary/15 tints that one bar, so a class picked by status colors every bar of that status. For a smaller mark, give GanttFeatureItem content of its own, which replaces its label, such as a dot in the status color before the name, as the Status colors demo does.

When should I use a Gantt chart instead of a calendar or a kanban board?

Use a Gantt chart when work has a start and an end and the overlaps matter: a roadmap, a sprint, a launch with milestones. Each feature is a bar, and you can see it slide past a deadline.

A Calendar suits picking a day or showing what falls on a date. A Kanban board suits work that moves between stages, where the column a card sits in matters more than its dates.

API Reference

GanttProvider

PropType
locale?string

The locale the header, the durations and the dates read in.

Default
"en-US"
onAddItem?(date: Date) → void

Called with the day under the pointer when someone clicks an empty spot of the timeline. Without it, the timeline has no add helper.

Parameters

date – Date

Returns
void
range?GanttRange

What a column is: a day (daily), a month under its year (monthly) or a month under its quarter (quarterly).

Default
"monthly"
zoom?number

The columns' width in percent: 150 makes every column half as wide again.

Default
100
className?string

Merged with the part's classes.

GanttSidebar

<div> data-slot="gantt-sidebar"

PropType
durationHeading?string

The duration column's heading.

Default
"Duration"
heading?string

The feature column's heading.

Default
"Issues"
className?string

Merged with the part's classes.

CSS variableType
--gantt-header-heightstring
--gantt-sidebarstring

GanttSidebarGroup

<div> data-slot="gantt-sidebar-group"

PropType
namestring

The group's name, on the row above its items.

className?string

Merged with the part's classes.

CSS variableType
--gantt-row-heightstring

GanttSidebarItem

<button> data-slot="gantt-sidebar-item"

PropType
featureobject

The feature this row names: its status, name and length.

Type
{ endAt: Date; id: string; name: string; startAt: Date; status: GanttStatus }
onSelectItem?(id: string) → void

Called with the feature's id when the row is chosen, after the chart scrolls to it.

Parameters

id – string

Returns
void
className?string

Merged with the part's classes.

CSS variableType
--gantt-row-heightstring
--gantt-statusstring

GanttTimeline

<div> data-slot="gantt-timeline"

PropType
className?string

Merged with the part's classes.

AttributeType
data-weekend?string
CSS variableType
--gantt-add-xstring
--gantt-add-ystring
--gantt-column-widthstring
--gantt-header-heightstring
--gantt-row-heightstring

GanttHeader

data-slot="gantt-header"

PropType
className?string

Merged with the part's classes.

AttributeType
data-weekend?string
CSS variableType
--gantt-column-widthstring
--gantt-header-heightstring
--gantt-sidebarstring

GanttFeatureList

<div> data-slot="gantt-feature-list"

PropType
className?string

Merged with the part's classes.

GanttFeatureListGroup

<div> data-slot="gantt-feature-list-group"

PropType
className?string

Merged with the part's classes.

CSS variableType
--gantt-row-heightstring

GanttFeatureItem

<div> data-slot="gantt-feature-item"

PropType
endAtDate

The feature's last day, included.

idstring

The element's id.

namestring

The bar's label when it has no children, and its name for assistive tech.

startAtDate

The feature's first day.

onMove?(id: string, startAt: Date, endAt: Date) → void

Called with the new dates when a drag or a key moves or resizes the bar. Keep them in state: the bar draws the dates it's given. Without it, the bar stays put, and it's text rather than a button.

Type
(id: string, startAt: Date, endAt: Date) → void
Parameters

id – string

startAt – Date

endAt – Date

Returns
void
className?string

Merged with the part's classes.

AttributeType
data-dragging?string
data-movable""
Default
""
CSS variableType
--gantt-feature-startstring
--gantt-feature-widthstring
--gantt-row-heightstring
--gantt-sidebarstring

GanttMarker

<div> data-slot="gantt-marker"

PropType
dateDate

The day the marker stands on.

idstring

The marker's id, passed back to onRemove.

labelstring

The milestone's name, shown on its flag under the header.

onRemove?(id: string) → void

Called with the marker's id from its remove button; without it, there is none.

Parameters

id – string

Returns
void
className?string

Merged with the part's classes.

CSS variableType
--gantt-header-heightstring
--gantt-marker-xstring

GanttToday

<div> data-slot="gantt-today"

PropType
label?string

The label over today's line.

Default
"Today"
className?string

Merged with the part's classes.

CSS variableType
--gantt-header-heightstring
--gantt-marker-xstring

GanttCreateMarkerTrigger

<div> data-slot="gantt-create-marker-trigger"

PropType
onCreateMarker(date: Date) → void

Called with the chosen day.

Parameters

date – Date

Returns
void
className?string

Merged with the part's classes.

CSS variableType
--gantt-header-heightstring
--gantt-pick-xstring