elefcode
← All cheat sheets

Tools

Mermaid Cheat Sheet — Diagram Syntax Reference

Mermaid draws diagrams from text in GitHub, GitLab, Notion, and most docs tools. This sheet covers the syntax for the diagram types you will use most.

Put it into practice with the matching tool.

Write a Mermaid diagram →

Advertisement

Flowchart

flowchart TDTop-down flowchart (LR, RL, BT for other directions)
A[Box] B(Rounded) C{Decision}Node shapes
D([Stadium]) E[(Database)] F((Circle))More node shapes
A --> BArrow
A -- yes --> B / A -->|yes| BArrow with a label
A -.-> B / A ==> BDotted / thick arrow
A --- BLine without an arrowhead
subgraph Name ... endGroup nodes in a box
classDef hot fill:#f96; class A hotDefine and apply a style class

Sequence diagram

sequenceDiagramStart a sequence diagram
participant A as BrowserDeclare a participant with an alias
A->>B: RequestSolid arrow message
B-->>A: ResponseDashed reply arrow
activate B / deactivate BShow an activation bar
Note over A,B: textNote spanning participants
alt ok ... else error ... endAlternative paths (also opt, loop, par)

ER diagram

erDiagramStart an entity-relationship diagram
USER ||--o{ ORDER : placesOne user places zero or more orders
|| |o }o }|Exactly one / zero or one / zero or more / one or more
USER { int id PK string email }Entity attributes with keys

Class and state diagrams

classDiagramStart a class diagram
Animal <|-- DogInheritance
class Dog { +bark() void }Class with a method
stateDiagram-v2Start a state diagram
[*] --> IdleInitial state
Idle --> Busy : startTransition with a label

Gantt and pie

gantt dateFormat YYYY-MM-DDStart a Gantt chart
section BuildGroup tasks
Design :a1, 2026-11-01, 5dTask with an ID, start date, and duration
Code :after a1, 10dTask that starts after another
pie title Traffic "Search" : 60Pie chart with labelled values

General

%% commentComment line
```mermaidFence that renders on GitHub and GitLab
A["Text with (brackets)"]Quote labels that contain special characters

Related guides

More cheat sheets