Cheatsheet: MermaidJS

Find diagram syntax, copy a complete example, and open it in the playground to make it your own.

Updated

How to use

Examples target the Mermaid 10.9 engine used by this playground.

Complete diagrams
Every copy target includes its diagram declaration and required nodes or participants. Paste the whole block into the playground.
See the result
Expand Example for a live preview and syntax notes. Open the same source in the playground for editing, sharing, and export.
Markdown hosts
In a host that supports Mermaid, wrap the source in a fenced code block labelled mermaid. Do not paste the backtick fences into this playground.
Versions and configuration
Hosts may use different Mermaid versions or restrict configuration and links. Newer syntax from Mermaid 11 may not work in this playground.
Open playground

Start here

Choose a direction and connect your first two nodes.

Draw a left-to-right flowchart

flowchart LR
  A[Request] --> B[Response]

Node shapes

Keep a stable node ID and change the surrounding label syntax.

Use a rounded rectangle

flowchart LR
  step(Process order)

Show a decision

flowchart TD
  ready{Ready?}
  ready -->|Yes| ship[Ship]
  ready -->|No| wait[Wait]

Edges and labels

Show direction, plain connections, and labelled relationships.

Label different edge styles

flowchart LR
  A -->|Request| B
  B -.->|Optional| C
  C ==>|Result| D

Groups and styles

Group related nodes and reuse visual styles.

Group nodes into subgraphs

flowchart TD
  subgraph client [Client]
    A[Browser] --> B[Cache]
  end
  subgraph server [Server]
    C[API] --> D[(Database)]
  end
  B --> C

Style one node

flowchart LR
  A[Important] --> B[Next]
  style A fill:#e6f2ff,stroke:#2563eb,color:#0b1220,stroke-width:2px

Reuse a style class

flowchart LR
  A[Check] --> B[Approve]
  classDef step fill:#e6f2ff,stroke:#2563eb,color:#0b1220
  class A,B step

Assign a class inline

flowchart LR
  A[Check]:::step --> B[Approve]
  classDef step fill:#e6f2ff,stroke:#2563eb,color:#0b1220

Sequence messages

Declare participants, send requests, and show replies or active work.

Name participants

sequenceDiagram
  actor U as User
  participant API as API server
  U->>API: Fetch profile
  API-->>U: Profile

Choose message line types

sequenceDiagram
  Alice->Bob: Solid line, no arrowhead
  Bob-->Alice: Dashed line, no arrowhead
  Alice->>Bob: Solid arrow
  Bob-->>Alice: Dashed reply

Activate and deactivate explicitly

sequenceDiagram
  Alice->>Bob: Request
  activate Bob
  Bob-->>Alice: Response
  deactivate Bob

Use activation shorthand

sequenceDiagram
  Alice->>+Bob: Request
  Bob-->>-Alice: Response

Add notes around participants

sequenceDiagram
  Note left of Alice: Session starts
  Alice->>Bob: Authenticate
  Note over Alice,Bob: Handshake in progress
  Bob-->>Alice: Token

Sequence control flow

Show alternatives, repeated requests, and parallel work.

Show alternative paths

sequenceDiagram
  Client->>API: Sign in
  alt Valid credentials
    API-->>Client: Token
  else Invalid credentials
    API-->>Client: Error
  end

Repeat and number messages

sequenceDiagram
  autonumber
  loop Every minute
    Client->>API: Poll status
    API-->>Client: Status
  end

Show parallel work

sequenceDiagram
  par Load account
    UI->>Account: Fetch
    Account-->>UI: Account data
  and Load settings
    UI->>Settings: Fetch
    Settings-->>UI: Settings data
  end

Class diagrams

Describe fields, methods, and relationships between types.

Define fields and methods

classDiagram
  class Person {
    +String name
    -int age
    +speak() String
  }

Show class relationships

classDiagram
  Animal <|-- Dog : inheritance
  Car *-- Engine : composition
  Team o-- Player : aggregation
  Student --> Course : association

ER and state diagrams

Model database relationships or transitions through a lifecycle.

Model database relationships

erDiagram
  USER ||--o{ ORDER : places
  USER {
    int id PK
    string email
  }
  ORDER {
    int id PK
    int user_id FK
    string status
  }

Draw a state machine

stateDiagram-v2
  [*] --> Draft
  Draft --> Review : submit
  Review --> Published : approve
  Review --> Draft : revise
  Published --> [*]

Charts and timelines

Show proportions, project dates, or a Git branch history.

Show proportions in a pie chart

pie title Example workload
  "Build" : 50
  "Review" : 30
  "Test" : 20

Plan tasks with a Gantt chart

gantt
  title Release plan
  dateFormat YYYY-MM-DD
  section Build
    Implementation :done, impl, 2026-09-01, 4d
    QA :active, qa, after impl, 3d

Show a branch and merge

gitGraph
  commit
  branch feature
  commit
  checkout main
  merge feature

Syntax pitfalls

Avoid parser surprises with labels, reserved words, and comments.

Separate IDs from readable labels

flowchart LR
  api_gateway["API Gateway (v2)"] --> user_service["User Service"]

Use comments and safe endpoint labels

flowchart TD
  %% Comments go on their own line
  start[Start] --> finish["end"]

FAQ