Mermaid Sequence Diagram Guide
Participants, messages, loops, and alt blocks — with copy-paste examples
Basic Sequence Diagram
A sequence diagram shows how components communicate over time. Messages flow from left to right between named participants.
->> is a solid arrow (request). -->> is a dotted arrow (response).
Arrow Types
->>— solid with arrowhead (synchronous call)-->>— dotted with arrowhead (response)-)— solid with open end (async fire-and-forget)--)— dotted with open end-x— solid with cross (lost/failed message)--x— dotted with cross
Participants and Aliases
Declare participants explicitly to control their order and give them readable labels:
Activation Bars
Show when a participant is actively processing with activate/deactivate or the shorthand +/-:
The + after ->> activates the target. The - deactivates it on the return arrow.
Loops
Wrap repeated messages in a loop block:
Conditional Logic (alt/opt)
Use alt for if/else and opt for optional blocks:
Notes
Add explanatory notes to diagrams:
Note right of X:— note to the rightNote left of X:— note to the leftNote over X,Y:— note spanning participants
Real-World Example: OAuth 2.0 Flow
Tips
- Always declare participants explicitly to control column order
- Use aliases (
participant A as API Gateway) for readable labels - Use activation bars to show request/response spans
- Group related messages with
rectfor visual highlighting - Keep diagrams focused — one flow per diagram
For more diagram types, see What Is Mermaid? and Mermaid Flowcharts.
View Sequence Diagrams with MDViewer
MDViewer renders sequence diagrams as interactive SVGs with zoom and full-screen. Paste any example into a .md file and open it.
Requires macOS 13.0 or later. Intel and Apple Silicon.