Mermaid Cheat Sheet

2026-11-15

Pick a diagram type by what you want to express: think about the relationship first, then choose.

Cheat sheet

To express Diagram Declaration
Steps and branches Flowchart graph TD or graph LR
Messages between actors Sequence sequenceDiagram
State transitions State stateDiagram-v2
Classes and inheritance Class classDiagram
Data entity relations ER erDiagram
Schedules and milestones Gantt gantt
Composition shares Pie pie

Flowchart

graph LR
    Setup --> Conflict --> Twist --> Ending

Direction letters: TD top-down, LR left-to-right.

Sequence diagram

sequenceDiagram
    Reader->>Author: follows updates
    Author-->>Reader: posts two chapters

State and ER diagrams

stateDiagram-v2
    [*] --> Serializing
    Serializing --> Completed: book finished
erDiagram
    Reader ||--o{ Review : writes
    Work ||--o{ Review : receives

Gantt and pie

gantt
    Three-volume writing plan
    Volume 1 :done, vol1, 2026-01-01, 60d
    Volume 2 :active, vol2, after vol1, 60d
    Volume 3 :vol3, after vol2, 60d
pie
    Writing time split
    Drafting : 50
    Research : 30
    Revising : 20

When a render fails, check the declaration line first; diagram data lives in the Markdown source, so edits re-render any time.