Mermaid reference
Mermaid cheat sheet
The syntax you need for flowcharts and sequence diagrams, the two Mermaid types most people write, on one page. Each example below is drawn live by Mermaid; click “Edit and export” to change it.
Updated
flowchart LR
start([Request received]) --> check{Complete?}
check -->|Yes| review[Review]
check -->|No| ask[/Ask for missing info/]
ask -.-> check
review ==> done([Approved])
review --> db[(Archive)]sequenceDiagram
autonumber
actor U as User
participant App
participant API
U->>App: Tap "Pay"
App->>+API: POST /payments
alt card accepted
API-->>App: 200 OK
else card declined
API-->>App: 402 Payment Required
end
deactivate API
Note over App,API: Retries are handled by the appFlowchart basics
flowchart TD
A[Start] --> B{Ready?}
B -->|Yes| C[Go]
B -->|No| A| You write | You get |
|---|---|
flowchart TD (or TB) | Top to bottom |
flowchart LR | Left to right |
flowchart BT / RL | Bottom to top / right to left |
A[Text] | Node with id A and a label |
A["Text (with) symbols"] | Quoted label: any character is allowed |
A --> B --> C | A chain of links on one line |
A & B --> C | Two links at once |
%% note to self | Comment, not drawn |
graph TD still works and means the same thing; flowchart is the newer keyword and supports more features.
Links (arrows)
| Syntax | Drawn as |
|---|---|
A --> B | Arrow |
A --- B | Line, no arrowhead |
A -.-> B | Dotted arrow |
A ==> B | Thick arrow |
A --o B / A --x B | Circle or cross end |
A <--> B | Arrow at both ends |
A ~~~ B | Invisible link (only to influence the layout) |
A -->|Yes| B or A -- Yes --> B | Arrow with a label |
A ---> B | Longer link: one extra dash per extra rank |
Node shapes
| Syntax | Shape | Typical meaning |
|---|---|---|
[text] | Rectangle | Step, process |
(text) | Rounded rectangle | Event, soft step |
([text]) | Stadium | Start or end |
{text} | Diamond | Decision |
[(text)] | Cylinder | Database, storage |
[/text/] | Parallelogram | Input or output |
[[text]] | Subroutine | Sub-process defined elsewhere |
((text)) | Circle | Connector |
{{text}} | Hexagon | Preparation |
All shapes, including the newer @{ shape: … } syntax with document, delay and manual-input shapes, are on the flowchart shapes page.
Groups and styling
flowchart LR
subgraph team [Design team]
a[Brief] --> b[Mockup]
end
b --> c[Build]:::urgent
classDef urgent fill:#fde2e2,stroke:#c0392b
style a stroke-width:3pxA subgraph ends with end on its own line. classDef defines a reusable style, :::name applies it to one node, style styles a single node. More on groups in Mermaid subgraphs.
Sequence diagram basics
| Syntax | Meaning |
|---|---|
participant API / actor U as User | Declare a box or a stick figure, with an optional display name |
A->>B: text | Request (solid arrow) |
B-->>A: text | Reply (dotted arrow) |
A-)B: text | Asynchronous message (open arrowhead) |
A-xB: text | Message that fails (cross) |
A->>+B … B-->>-A | Activate and deactivate B |
Note right of A: text / Note over A,B: text | Note beside or across lifelines |
loop, alt/else, opt, par/and, critical, break … end | Blocks |
autonumber | Number every message |
Worked examples of each block are on the sequence diagram page.
Five rules that prevent most errors
- Quote any label that contains
( ) [ ] { } " ;or starts with a symbol:A["Total (EUR)"]. - Never name a node
endin lowercase: it closes subgraphs and blocks. - Use two dashes in flowcharts:
-->, never->. - Keep node ids to one word:
orderPaid[Order paid], notorder paid. - In sequence diagrams, always put a colon before the message text, and no
;inside it.
If a diagram still won't render, paste it in the Mermaid syntax checker.
Describe it in words instead
Paste notes about a process, a team or an exchange between systems. Arrowly draws the flowchart, org chart or sequence diagram and gives you Mermaid code that always parses. 3 free diagrams a day, no signup.
Draw from my notes