Use Mermaid Block
A mermaid Block supports multiple diagram types, including flowcharts, sequence diagrams, class diagrams, state diagrams, Gantt charts, and more.
Insert a mermaid block by typing ::mermaid in the editor and press enter. A blank block will appear. By clicking on it, you’ll be able to edit its contents, much like with the math block.
Flowcharts
graph TD
    A[Start] --> B[Process]
    B --> C{Decision}
    C -->|Yes| D[Result 1]
    C -->|No| E[Result 2]
graph Dspecifies the direction of the flowchart (top to bottom in this case). You can also useLR for left to right,RL for right to left, andBT for bottom to top.A[Start]creates a node labeled “Start”.-->creates a directed link from one node to another.{Decision}creates a decision node (diamond-shaped).--> |Yes|creates a conditional link labeled “Yes”.
Sequence Diagrams
sequenceDiagram
    participant A as Alice
    participant B as Bob
    A->>B: Hello Bob, how are you?
    B-->>A: I am good thanks!
    Note right of B: Bob thinks
    B->>C: How about you?
    C-->>B: I'm fine too!
sequenceDiagramspecifies the start of a sequence diagram.participant Aas Alice defines a participant with a display name.A->>B: Messagesends a message from A to B.Note right of Badds a note to the right of participant B.
Advanced Sequence Diagrams
Sequence diagrams can be enhanced with loops, alternatives (alt), and options (opt).
sequenceDiagram
    participant A as Alice
    participant B as Bob
    A->>B: Hello Bob
    alt Is Bob busy?
        B-->>A: Yes, I am busy
    else
        B-->>A: No, I am free
        opt Extra time?
            B-->>A: Let's grab a coffee
        end
    end
    loop Daily routine
        B-->>A: Check email
    end
alt ... elsecreates an alternative block with conditions.optcreates an optional block.loopcreates a loop block.
Class Diagrams
classDiagram
    class Animal {
        +String name
        +int age
        +makeSound()
    }
    class Dog {
        +String breed
    }
    Animal <|-- Dog
classDiagramspecifies the start of a class diagram.class Animal {}defines a class named Animal.+String namedefines a public attribute.+makeSound()defines a public method.Animal <-- Dogindicates inheritance, where Dog inherits from Animal.
State Diagrams
stateDiagram
    [*] --> Idle
    Idle --> Processing : Event1
    Processing --> Done : Event2
    Done --> [*]
stateDiagramspecifies the start of a state diagram.[ * ]represents the start state.Idle --> Processing : Event1defines a transition from Idle to Processing triggered by Event1.
Gantt Charts
gantt
    title A Gantt Diagram
    dateFormat  YYYY-MM-DD
    section Section
    Task1           :a1, 2023-01-01, 30d
    Task2           :after a1  , 20d
    Task3           : 2023-01-15, 25d
ganttspecifies the start of a Gantt chart.titlesets the title of the chart.dateFormatspecifies the date format.sectiondefines a section of tasks.Task1 :a1, 2023-01-01, 30ddefines a task with anID, start date, and duration.:after a1schedules the task to start after task a1 completes.
Pie Charts
Pie charts are used to represent data in a circular graph.
pie
    title Pie Chart Example
    "Category A" : 40
    "Category B" : 20
    "Category C" : 30
    "Category D" : 10
piespecifies the start of a pie chart.titlesets the title of the chart."Category A" : 40defines a segment of the pie chart with alabel and value.
Entity Relationship Diagrams (ERD)
ERDs are used to represent the relationships between entities in a database.
erDiagram
    CUSTOMER ||--o{ ORDER : places
    CUSTOMER {
        string name
        string address
    }
    ORDER {
        int id
        string product
        int quantity
    }
erDiagramspecifies the start of an ER diagram.CUSTOMER ||--o{ ORDER : placesdefines a relationship where a customer places orders.CUSTOMER {}defines an entity with attributes.int iddefines an attribute with a type.
Commit Flow Diagram
gitGraph
   commit
   branch develop
   checkout develop
   commit
   commit
   branch feature-1
   checkout feature-1
   commit
   checkout develop
   merge feature-1
   commit
   checkout main
   merge develop
   commit
gitGraphspecifies the start of a commit flow diagram.commitcreates a commit.branch developcreates a new branch named develop.checkout developswitches to the develop branch.merge feature-1merges thefeature-1branch into thecurrent branch.
User Journey Diagram
journey
    title User Journey for Booking a Flight
    section Search
      User searches for flights: 5: User
    section Select
      User selects a flight: 5: User
      System shows flight details: 3: System
    section Book
      User enters passenger details: 5: User
      System confirms booking: 4: System
journeyspecifies the start of a user journey diagram.sectioncreates a new section in the journey.User searches for flights: 5: Userdescribes an action, arating, and an actor.
Quadrant Chart
quadrantChart
    title Reach and engagement of campaigns
    x-axis Low Reach --> High Reach
    y-axis Low Engagement --> High Engagement
    quadrant-1 We should expand
    quadrant-2 Need to promote
    quadrant-3 Re-evaluate
    quadrant-4 May be improved
    Campaign A: [0.3, 0.6]
    Campaign B: [0.45, 0.23]
    Campaign C: [0.57, 0.69]
    Campaign D: [0.78, 0.34]
    Campaign E: [0.40, 0.34]
    Campaign F: [0.35, 0.78]
quadrantChartspecifies the start of a quadrant chart.title Reach and Engagement of Campaignssets the title of the chart.x-axis Low Reach --> High Reachlabels thex-axiswith a range.y-axis Low Engagement --> High Engagement labelsthey-axiswith a range.quadrant-1: We should expandtoquadrant-4: May be improvedlabel the four quadrants."Campaign A" : [0.3, 0.6]plots a point representing Campaign A with specific coordinates.
XY Chart (XYChart-Beta)
xychart-beta
    title "Sales Revenue"
    x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
    y-axis "Revenue (in $)" 4000 --> 11000
    bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
    line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
xychart-betaspecifies the start of an XY chart.title "Sales Revenue"sets the title of the chart.x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]labels the x-axis with months.y-axis "Revenue (in $)" 4000 --> 11000labels the y-axis with a range for revenue.bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]plots a bar chart with the given data points.line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]plots a line chart with the same data points.