Mermaid Syntax Cheat Sheet

The most-used Mermaid syntax on one page, with a rendered example for each diagram type. Print it or save it as PDF with the button below; no email required.

Flowchart

CodeMeaning
graph TD / flowchart LRDeclare and set direction: TD, TB, BT, LR, RL
A[Box] B(Round) C{Decision} D[(DB)]Node shapes
A --> B A -.-> B A ==> BArrow, dotted, thick
A -->|label| BLabeled arrow
subgraph id [Title] ... endGroup nodes
classDef c fill:#eee; A:::cReusable styles
Rendering diagram…
Mermaid code
graph TD
  A[Start] --> B{OK?}
  B -->|Yes| C[Done]
  B -->|No| D[Retry] --> B

Sequence diagram

CodeMeaning
participant A as Alice / actor UParticipants
A->>B: call B-->>A: replySolid and dotted messages
A-)B: event A-xB: failedAsync and failed messages
alt ... else ... endBranches (also opt, loop, par, critical)
Note over A,B: textNotes
autonumberNumber the messages
Rendering diagram…
Mermaid code
sequenceDiagram
  Alice->>Bob: Hello
  Bob-->>Alice: Hi!
  Note over Alice,Bob: Greeting

Class diagram

CodeMeaning
class A { +int id; -save() }Members with visibility + - # ~
A <|-- BInheritance
A *-- B A o-- BComposition, aggregation
A --> B A ..> BAssociation, dependency
List~T~Generics
Rendering diagram…
Mermaid code
classDiagram
  Animal <|-- Dog
  class Dog {
    +String name
    +bark()
  }

State diagram

CodeMeaning
stateDiagram-v2Declare
[*] --> A A --> [*]Start and end
A --> B : eventTransition with label
state A { ... }Composite state
state c <<choice>>Choice; also <<fork>> and <<join>>
Rendering diagram…
Mermaid code
stateDiagram-v2
  [*] --> Idle
  Idle --> Busy : start
  Busy --> Idle : done

ER diagram

CodeMeaning
A ||--o{ B : hasOne A to zero or more B (label required)
|| |o }o }|One, zero or one, zero or more, one or more
-- ..Identifying, non-identifying
A { int id PK }Attributes with PK, FK, UK
Rendering diagram…
Mermaid code
erDiagram
  USER ||--o{ POST : writes
  USER {
    int id PK
    string name
  }

Gantt chart

CodeMeaning
dateFormat YYYY-MM-DDInput date format
section NameGroup tasks
Task :t1, 2026-01-05, 3dID, start, duration
Task :after t1, 2dDependency
done / active / crit / milestoneTags before the ID
Rendering diagram…
Mermaid code
gantt
  dateFormat YYYY-MM-DD
  section Work
  Plan  :done, p1, 2026-01-05, 3d
  Build :active, after p1, 5d

Pie chart

CodeMeaning
pie showDataDeclare, optionally showing values
title TextTitle
"Label" : 42Slice
Rendering diagram…
Mermaid code
pie title Pets
  "Dogs" : 45
  "Cats" : 35
  "Fish" : 20

Mindmap

CodeMeaning
mindmapDeclare; the first node is the root
IndentationChildren are indented under their parent
id((circle)) id[square] id)cloud(Shapes
Rendering diagram…
Mermaid code
mindmap
  root((Trip))
    Book flights
    Hotel
      Downtown
    Packing

Timeline

CodeMeaning
timelineDeclare
2026 : Event : Another eventPeriod and events
section NameGroup periods
Rendering diagram…
Mermaid code
timeline
  2024 : Idea
  2025 : Beta : Launch
  2026 : Version 2

Git graph

CodeMeaning
commit id: "msg" tag: "v1"Commit
branch dev / checkout devCreate and switch branches
merge devMerge into the current branch
Rendering diagram…
Mermaid code
gitGraph
  commit
  branch dev
  commit
  checkout main
  merge dev

Themes and configuration

A YAML front matter block at the top of the code sets the theme and other options for that diagram only.

CodeMeaning
config: theme: forestThemes: default, neutral, dark, forest, base
title: My diagramTitle shown above most diagram types
%% commentComment line
Rendering diagram…
Mermaid code
---
title: Release flow
config:
  theme: forest
---
graph LR
  Dev --> Staging --> Production

Frequently asked questions

Can I download this Mermaid cheat sheet as a PDF?

Yes. Use the Print / Save as PDF button at the top of the page and choose Save as PDF in the print dialog. No email address is required.

Which Mermaid version does this cheat sheet cover?

Mermaid 11, the version this editor runs. Everything here also works in recent Mermaid 10 releases.

Where can I find the full syntax for one diagram type?

Each diagram type has its own page with a full syntax table, examples and common errors. Follow the links in the list of diagram types.