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
| Code | Meaning |
|---|---|
graph TD / flowchart LR | Declare and set direction: TD, TB, BT, LR, RL |
A[Box] B(Round) C{Decision} D[(DB)] | Node shapes |
A --> B A -.-> B A ==> B | Arrow, dotted, thick |
A -->|label| B | Labeled arrow |
subgraph id [Title] ... end | Group nodes |
classDef c fill:#eee; A:::c | Reusable styles |
Rendering diagram…
Mermaid code
graph TD
A[Start] --> B{OK?}
B -->|Yes| C[Done]
B -->|No| D[Retry] --> BSequence diagram
| Code | Meaning |
|---|---|
participant A as Alice / actor U | Participants |
A->>B: call B-->>A: reply | Solid and dotted messages |
A-)B: event A-xB: failed | Async and failed messages |
alt ... else ... end | Branches (also opt, loop, par, critical) |
Note over A,B: text | Notes |
autonumber | Number the messages |
Rendering diagram…
Mermaid code
sequenceDiagram
Alice->>Bob: Hello
Bob-->>Alice: Hi!
Note over Alice,Bob: GreetingClass diagram
| Code | Meaning |
|---|---|
class A { +int id; -save() } | Members with visibility + - # ~ |
A <|-- B | Inheritance |
A *-- B A o-- B | Composition, aggregation |
A --> B A ..> B | Association, dependency |
List~T~ | Generics |
Rendering diagram…
Mermaid code
classDiagram
Animal <|-- Dog
class Dog {
+String name
+bark()
}State diagram
| Code | Meaning |
|---|---|
stateDiagram-v2 | Declare |
[*] --> A A --> [*] | Start and end |
A --> B : event | Transition 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 : doneER diagram
| Code | Meaning |
|---|---|
A ||--o{ B : has | One 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
| Code | Meaning |
|---|---|
dateFormat YYYY-MM-DD | Input date format |
section Name | Group tasks |
Task :t1, 2026-01-05, 3d | ID, start, duration |
Task :after t1, 2d | Dependency |
done / active / crit / milestone | Tags 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, 5dPie chart
| Code | Meaning |
|---|---|
pie showData | Declare, optionally showing values |
title Text | Title |
"Label" : 42 | Slice |
Rendering diagram…
Mermaid code
pie title Pets
"Dogs" : 45
"Cats" : 35
"Fish" : 20Mindmap
| Code | Meaning |
|---|---|
mindmap | Declare; the first node is the root |
Indentation | Children are indented under their parent |
id((circle)) id[square] id)cloud( | Shapes |
Rendering diagram…
Mermaid code
mindmap
root((Trip))
Book flights
Hotel
Downtown
PackingTimeline
| Code | Meaning |
|---|---|
timeline | Declare |
2026 : Event : Another event | Period and events |
section Name | Group periods |
Rendering diagram…
Mermaid code
timeline
2024 : Idea
2025 : Beta : Launch
2026 : Version 2Git graph
| Code | Meaning |
|---|---|
commit id: "msg" tag: "v1" | Commit |
branch dev / checkout dev | Create and switch branches |
merge dev | Merge into the current branch |
Rendering diagram…
Mermaid code
gitGraph
commit
branch dev
commit
checkout main
merge devThemes and configuration
A YAML front matter block at the top of the code sets the theme and other options for that diagram only.
| Code | Meaning |
|---|---|
config: theme: forest | Themes: default, neutral, dark, forest, base |
title: My diagram | Title shown above most diagram types |
%% comment | Comment line |
Rendering diagram…
Mermaid code
---
title: Release flow
config:
theme: forest
---
graph LR
Dev --> Staging --> ProductionFrequently 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.