← Back to Editor All Tutorials
中文

Mermaid Cheat Sheet

A complete reference for Mermaid diagram syntax covering all supported diagram types. Click navigation to jump to specific diagram types.

Flowchart

flowchart TD
    %% Node definitions
    A[Start]
    B{Decision}
    C[Process]
    D((End))

    %% Connections
    A --> B
    B -->|Yes| C
    B -->|No| D
    C --> D

    %% Subgraph
    subgraph Subprocess
        C --> E[Step 1]
        E --> F[Step 2]
    end
Try in MermZen →
SyntaxDescription
flowchart TDTop Down
flowchart LRLeft Right
flowchart BTBottom Top
flowchart RLRight Left
A[Text]Rectangle
A(Text)Rounded rectangle
A((Text))Circle
A{Text}Rhombus (decision)
A[/Text/]Parallelogram
A --> BSolid arrow
A -.-> BDotted arrow
A ==> BThick arrow
A --text--> BLabeled arrow

Sequence Diagram

sequenceDiagram
    actor User
    participant Frontend
    participant API
    participant Database

    User->>Frontend: Click login
    Frontend->>API: POST /login
    API->>Database: Query user
    Database-->>API: Return data
    API-->>Frontend: Return token
    Frontend-->>User: Login success

    %% Loop
    loop Retry mechanism
        API->>Database: Retry query
    end

    %% Conditional
    alt User exists
        API-->>Frontend: Normal response
    else User not found
        API-->>Frontend: Error response
    end
Try in MermZen →
SyntaxDescription
participant NameDefine participant
actor NameDefine actor
A->>B: msgSolid arrow (send)
A-->>B: msgDotted arrow (return)
A->>+B: msgActivate B
A-->>-B: msgDeactivate B
loop descLoop
alt conditionConditional branch
opt conditionOptional execution
par parallelParallel execution
rect rgb(255,0,0)Colored background

Class Diagram

classDiagram
    class Animal {
        +String name
        +int age
        +makeSound()
        +move()
    }

    class Dog {
        +breed
        +fetch()
    }

    class Cat {
        +color
        +climb()
    }

    Animal <|-- Dog : inherits
    Animal <|-- Cat : inherits
    Dog o-- Toy : aggregation
    Cat *-- Whisker : composition
Try in MermZen →
SyntaxDescription
class Name { }Define class
+propertyPublic attribute/method
-propertyPrivate attribute/method
#propertyProtected attribute/method
A <|-- BInheritance (B extends A)
A --* BComposition
A --o BAggregation
A --> BAssociation
A ..> BDependency
A --|> BImplementation
A "1" --> "*" BOne-to-many

Gantt Chart

gantt
    title Project Development Plan
    dateFormat  YYYY-MM-DD

    section Design Phase
    Requirements    :done, a1, 2026-01-01, 7d
    UI Design       :active, a2, after a1, 5d
    Review          :a3, after a2, 3d

    section Development
    Backend         :b1, after a3, 14d
    Frontend        :b2, after a3, 14d
    Integration     :b3, after b1, 5d

    section Testing
    Test            :c1, after b3, 7d
    Bug Fix         :c2, after c1, 5d
    Deploy          :milestone, c3, after c2, 1d
Try in MermZen →
SyntaxDescription
dateFormatDate format definition
section NamePhase grouping
:doneCompleted status
:activeIn progress status
:critCritical path
:milestoneMilestone
after taskDepends on previous task
7dDuration 7 days

Pie Chart

pie title Browser Market Share
    "Chrome" : 65.3
    "Safari" : 18.5
    "Firefox" : 6.2
    "Edge" : 5.1
    "Others" : 4.9
Try in MermZen →
SyntaxDescription
pie title TitleDeclare pie chart
"Label" : valueData item
showDataShow values

Mindmap

mindmap
  root((Project Management))
    Planning
      Requirements
      Resource allocation
      Scheduling
    Execution
      Development
      Testing
      Deployment
    Monitoring
      Progress tracking
      Risk management
Try in MermZen →
SyntaxDescription
root((Root))Root node
indent + nodeChild node (2 spaces)
::icon(icon)Add icon

User Journey

journey
    title Shopping User Journey
    section Browse Products
      Visit homepage: 5: User
      Search product: 4: User
      View details: 4: User
    section Order & Payment
      Add to cart: 5: User
      Fill address: 3: User
      Complete payment: 5: User, System
    section Delivery
      Track shipment: 4: User
      Confirm receipt: 5: User
Try in MermZen →
SyntaxDescription
section PhaseDefine phase
Task: Score: ActorTask (score 1-5)

Git Graph

gitGraph
    commit "Initial commit"
    branch feature/login
    commit "Login feature"
    commit "Login polish"
    checkout main
    branch feature/register
    commit "Register feature"
    checkout main
    merge feature/login tag: "v1.1.0"
    merge feature/register
Try in MermZen →
SyntaxDescription
gitGraphDeclare Git graph
commit "msg"Create commit
branch nameCreate branch
checkout branchSwitch branch
merge branchMerge branch
tag: "version"Create tag

ER Diagram

erDiagram
    CUSTOMER {
        string customer_id PK
        string name
        string email
    }
    ORDER {
        int order_id PK
        date order_date
        string customer_id FK
    }
    CUSTOMER ||--o{ ORDER : places
Try in MermZen →
SyntaxDescription
ENTITY { }Define entity
PKPrimary key
FKForeign key
||--o{One-to-many
||--||One-to-one
}|--|{Many-to-many

State Diagram

stateDiagram-v2
    [*] --> Pending
    Pending --> Shipped: Payment confirmed
    Pending --> Cancelled: Cancel order
    Shipped --> InTransit: Shipped
    InTransit --> Delivered: Arrived
    Delivered --> Completed: Confirmed
    Completed --> [*]
Try in MermZen →
SyntaxDescription
[*]Start/End state
A --> BState transition
state Name { }Composite state
State: noteState note

Common Directives

%% This is a comment

%% Theme settings
theme default
theme dark
theme forest
theme neutral
theme base

%% Hand-drawn style
%% Toggle in MermZen editor
Try in MermZen →
SyntaxDescription
%% commentLine comment
title TitleSet chart title
theme nameSet theme
subgraph NameSubgraph group
direction LR/TDSubgraph direction

💡 Tip: Try all diagrams in the MermZen editor with live preview and export to SVG/PNG.