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
  end
The request has two alternative outcomes. The alt and else branches separate a valid token from an expired one; end closes the block. Vertical order describes the conversation, not measured latency.

How to use this tool

  1. Start with the example in the editor and identify the elements that answer your question.
  2. Replace the sample labels and values, previewing after each structural change.
  3. Review the diagram at its intended reading size, then keep the source and export the format your document accepts.

Syntax and interpretation

ConceptHow to apply it
ParticipantsDeclare participants in a clear order and use labels that match the system documentation.
MessagesLabel requests and responses with actions or results. Different arrow styles should have a consistent meaning in your explanation.
Control blocksUse 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.