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: shapes, labels and three kinds of links Edit and export
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)]
Sequence diagram: numbering, activation and alt/else Edit and export
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 app

Flowchart basics

Minimal flowchart
flowchart TD
  A[Start] --> B{Ready?}
  B -->|Yes| C[Go]
  B -->|No| A
You writeYou get
flowchart TD (or TB)Top to bottom
flowchart LRLeft to right
flowchart BT / RLBottom 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 --> CA chain of links on one line
A & B --> CTwo links at once
%% note to selfComment, not drawn

graph TD still works and means the same thing; flowchart is the newer keyword and supports more features.

Links (arrows)

SyntaxDrawn as
A --> BArrow
A --- BLine, no arrowhead
A -.-> BDotted arrow
A ==> BThick arrow
A --o B / A --x BCircle or cross end
A <--> BArrow at both ends
A ~~~ BInvisible link (only to influence the layout)
A -->|Yes| B or A -- Yes --> BArrow with a label
A ---> BLonger link: one extra dash per extra rank

Node shapes

SyntaxShapeTypical meaning
[text]RectangleStep, process
(text)Rounded rectangleEvent, soft step
([text])StadiumStart or end
{text}DiamondDecision
[(text)]CylinderDatabase, storage
[/text/]ParallelogramInput or output
[[text]]SubroutineSub-process defined elsewhere
((text))CircleConnector
{{text}}HexagonPreparation

All shapes, including the newer @{ shape: … } syntax with document, delay and manual-input shapes, are on the flowchart shapes page.

Groups and styling

Subgraph, class and style
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:3px

A 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

SyntaxMeaning
participant API / actor U as UserDeclare a box or a stick figure, with an optional display name
A->>B: textRequest (solid arrow)
B-->>A: textReply (dotted arrow)
A-)B: textAsynchronous message (open arrowhead)
A-xB: textMessage that fails (cross)
A->>+B … B-->>-AActivate and deactivate B
Note right of A: text / Note over A,B: textNote beside or across lifelines
loop, alt/else, opt, par/and, critical, break … endBlocks
autonumberNumber every message

Worked examples of each block are on the sequence diagram page.

Five rules that prevent most errors

  1. Quote any label that contains ( ) [ ] { } " ; or starts with a symbol: A["Total (EUR)"].
  2. Never name a node end in lowercase: it closes subgraphs and blocks.
  3. Use two dashes in flowcharts: -->, never ->.
  4. Keep node ids to one word: orderPaid[Order paid], not order paid.
  5. 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