Mermaid Gantt Chart Syntax & Examples
Reference for Mermaid Gantt chart syntax — dateFormat, sections, tasks, dependencies (after), milestones, and excludes. Copy-paste examples for release plans and roadmaps.
Use this page to connect a high-intent search query to the right problem-solution narrative.
A syntax reference for Mermaid's `gantt` grammar — read this when you need to know the exact way to declare a section, dependency, milestone, or excluded date range, then render the result in the editor.
View Mermaid sourcePlain-text diagram syntax — copy or edit directly.
1gantt2 title Release plan3 dateFormat YYYY-MM-DD4 section Backend5 API work :a1, 2026-04-01, 7d6 Migrations :a2, after a1, 3d7 section Frontend8 Landing pages :b1, 2026-04-03, 6d9 Editor polish :b2, after b1, 5d10 section Launch11 QA :c1, after a2, 4d12 GA :c2, after c1, 1dWhat is a Mermaid Gantt chart
A Mermaid Gantt chart describes a project schedule as horizontal bars on a timeline. Each row is a task; rows are grouped into sections (typically phases or teams); bars show duration; and dependency arrows can link tasks to predecessors. It is the right shape when the question is what-runs-when across multiple parallel work streams: release plans, sprint roadmaps, project schedules, deployment windows. If your story is a single chronology with no parallel streams, prefer a timeline; if it is a process with branches rather than parallel work, prefer a flowchart.
Header — title, dateFormat, axisFormat
Every Gantt chart starts with the `gantt` keyword. The first lines configure the chart: `title Plan name` sets the visible title. `dateFormat YYYY-MM-DD` declares how date strings in the source are parsed (ISO is the safest default). `axisFormat %Y-%m-%d` controls how dates render on the time axis (a more compact `%m-%d` is common for short plans). The `excludes weekends` directive removes Saturdays and Sundays from the rendered timeline, which is useful when work doesn't span weekends — task durations are computed as business days instead of calendar days.
- `title <Name>` — chart heading
- `dateFormat YYYY-MM-DD` — input date format (ISO is safest)
- `axisFormat %m-%d` — rendered time-axis labels (uses strftime tokens)
- `excludes weekends` — skip Sat/Sun in duration calculations
Sections — group related tasks
Use `section Name` to declare a section header. Subsequent task lines belong to that section until the next `section` declaration. Sections render as horizontal bands with the section name on the left. Pick sections by team (Backend / Frontend / Launch), by phase (Design / Build / Ship), or by track (Customer-facing / Internal) depending on what the chart is communicating. Sections also affect visual grouping in the legend, so a deliberate choice here makes the chart read as a plan rather than as an unorganised list of tasks.
Tasks — id, start, duration, dependencies
A task is a single line with the format `Task name :id, start, duration`. The id is used to reference the task as a dependency. The start can be an absolute date (`2026-05-01`) or relative to another task (`after a1` runs after task with id `a1` completes). The duration can be days (`5d`), weeks (`2w`), hours (`8h`), or an absolute end date. Multiple dependencies are written as `after a1 a2 a3` — the task starts after all listed predecessors finish. Tasks can also be flagged with state modifiers: `done` (greyed out), `active` (highlighted as in-progress), `crit` (critical path emphasis).
- `Task :id, 2026-05-01, 5d` — absolute start, day duration
- `Task :id, after a1, 3d` — start after another task completes
- `Task :crit, id, after a1, 5d` — flag as critical path
- `Task :done, id, 2026-04-01, 7d` — already completed
Milestones — zero-duration anchors
A milestone is a task with `0d` duration (or the `milestone` keyword). It renders as a diamond marker rather than a bar, which makes it visually distinct from work tasks. Use milestones for release dates, go/no-go decisions, freeze points, deployment cuts — the moments on the chart that are events rather than effort. The `milestone` keyword is shorthand: `GA :milestone, m1, after qa, 0d` produces the same diamond as the explicit `0d` form.
Common patterns & gotchas
Two patterns cover most real Gantt charts. Phase plans use sections per phase (Design / Build / QA / Ship), with each phase's tasks chained by `after` dependencies. Team plans use sections per team, with cross-team dependencies as the interesting edges to watch. The most common gotcha: `after a1` with a task that has no id — every task that will be referenced as a predecessor must have an explicit id (`Task :a1, 2026-05-01, 5d`). Second gotcha: forgetting to set `dateFormat` — Mermaid then guesses from the input and often picks differently than expected. Always declare `dateFormat YYYY-MM-DD` explicitly.
- Every task referenced by `after` must have an explicit id — the `a1` part of `:a1, start, duration`
- Always declare `dateFormat` explicitly — auto-detection is unreliable for non-ISO inputs
- Use `excludes weekends` for business-day duration math