Diagrams / Mermaid Sequence Diagram: Syntax & Examples
Mermaid Sequence Diagram: Syntax & Examples
Learn Mermaid sequence syntax with participants, messages and alternatives. Edit an API request example and distinguish event order from measured time.
When to use Sequence Diagram
Use a Mermaid sequence diagram to explain a conversation between actors or services over time. Put participants across the page and messages in reading order. Focus on one scenario so the reader can distinguish the normal path from alternatives and failures.
Read the Sequence Diagram example
Diagram source
sequenceDiagram
participant Client
participant API
Client->>API: Request profile
alt Valid token
API-->>Client: Return profile
else Expired token
API-->>Client: Reject request
endHow to use this tool
- Start with the example in the editor and identify the elements that answer your question.
- Replace the sample labels and values, previewing after each structural change.
- Review the diagram at its intended reading size, then keep the source and export the format your document accepts.
Syntax and interpretation
| Concept | How to apply it |
|---|---|
| Participants | Declare participants in a clear order and use labels that match the system documentation. |
| Messages | Label requests and responses with actions or results. Different arrow styles should have a consistent meaning in your explanation. |
| Control blocks | Use alt, loop, or other supported blocks for alternatives and repetition. Close each opened block with end. |
Common questions
Can I measure latency from the vertical spacing?
No. A sequence diagram normally communicates event order. Include explicit duration annotations or use a trace visualization when measured timing matters.