Use when drawing or editing Mermaid diagrams - flowcharts, sequence diagrams, class diagrams, state machines, ER diagrams, Gantt charts, gitgraphs, mindmaps, timelines, or any other Mermaid chart type
A --> B Arrow
A --- B Open line (no arrow)
A -->|label| B Arrow with label
A -- label --> B Arrow with label (alternate)
A -.-> B Dotted arrow
A -. label .-> B Dotted with label
A ==> B Thick arrow
A ~~~ B Invisible link (layout hint)
A --o B Circle at end
A --x B Cross at end
Add extra dashes/dots to increase edge length: A ----> B
Subgraphs
flowchart LR
subgraph frontend[Frontend]
direction TB
UI --> State
end
subgraph backend[Backend]
API --> DB
end
frontend --> backend
Styling
%% Inline style
style A fill:#4CAF50,stroke:#388E3C,color:#fff
%% Reusable class
classDef warning fill:#FFC107,stroke:#FF8F00,color:#000
class B,C warning
%% Shorthand attach
D:::warning
Gotchas
end is a reserved word — use End or END inside node labels
Node IDs starting with o or x can break arrow parsing — quote or capitalize
Special characters in labels must be quoted: A["text with (parens)"]
Subgraph direction is ignored when nodes have edges crossing outside the subgraph
Sequence Diagram
Participants
sequenceDiagram
participant C as Client
participant S as Server
actor U as User %% Stick figure icon
Participants render in declaration order. Declare them explicitly to control layout.
Message Arrows
Syntax
Style
Arrowhead
A->B: msg
Solid
None
A-->B: msg
Dotted
None
A->>B: msg
Solid
Open
A-->>B: msg
Dotted
Open
A-xB: msg
Solid
Cross (lost)
A--xB: msg
Dotted
Cross (lost)
A-)B: msg
Solid
Open async
A--)B: msg
Dotted
Open async
Activation
A->>+B: Request %% activate B
B-->>-A: Response %% deactivate B
%% Or explicit
activate B
deactivate B
Control Flow Blocks
loop Retry up to 3 times
C->>S: Request
S-->>C: Response
end
alt Success
S-->>C: 200 OK
else Error
S-->>C: 500 Error
end
opt Has Auth Token
C->>S: Bearer token
end
par In parallel
C->>S1: Call service 1
and
C->>S2: Call service 2
end
break On exception
S-->>C: 503 Unavailable
end
Notes
Note right of A: This is a note
Note over A,B: Spans two participants
Background Highlighting
rect rgb(191, 223, 255)
A->>B: Highlighted section
end
Autonumber
sequenceDiagram
autonumber
A->>B: First message
B-->>A: Second message
Class Diagram
Basic Class
classDiagram
class Animal {
+String name
-int age
#String species
~String habitat
+makeSound() String
+move()* void %% abstract
+breathe()$ void %% static
}
StateA : This is a note on StateA
note right of StateB
Multi-line note
on state B
end note
Entity Relationship Diagram
erDiagram
CUSTOMER {
int id PK
string name
string email UK
}
ORDER {
int id PK
int customerId FK
date placedAt
}
ORDER_ITEM {
int id PK
int orderId FK
int productId FK
int quantity
}
PRODUCT {
int id PK
string name
float price
}
CUSTOMER ||--o{ ORDER : "places"
ORDER ||--|{ ORDER_ITEM : "contains"
PRODUCT ||--o{ ORDER_ITEM : "included in"
Cardinality Reference
Left
Right
Meaning
|o
o|
Zero or one
||
||
Exactly one
}o
o{
Zero or more
}|
|{
One or more
Use -- (solid) for identifying relationships, .. (dashed) for non-identifying:
PARENT ||--o{ CHILD : "owns" %% identifying (solid)
USER }o..o{ ROLE : "assigned to" %% non-identifying (dashed)
mindmap
root
**Bold topic**
*Italic topic*
Multi-word
topic here
Timeline
timeline
title Product History
section Early Days
2020 : Founded
: MVP launched
section Growth
2021 : First enterprise customer
2022 : Series A
: Expanded to EU
section Today
2023 : 1M users
2024 : Series B
Pie Chart
pie title Traffic Sources
"Organic Search" : 42.5
"Direct" : 28.3
"Social" : 15.0
"Referral" : 14.2