Mermaid Diagram Examples: Flowchart, Sequence and ER Templates
Starting from a working diagram is faster than starting from the syntax reference. Below is one example per diagram type, each with the code to copy and a link that opens it in the Mermaid editor, where you can edit it and export PNG, SVG or PDF. The examples are the same ones the editor's template menu loads.
Flowchart template
A decision flow with a loop back. Change the labels and arrows to describe your own process.
flowchart TD
A[Start] --> B{Is it valid?}
B -->|Yes| C[Process data]
B -->|No| D[Show error]
C --> E[Save result]
D --> A
E --> F[End]Sequence diagram example
Messages between participants over time, in the order they happen.
sequenceDiagram
participant U as User
participant A as API
participant D as Database
U->>A: POST /login
A->>D: SELECT user
D-->>A: user row
A-->>U: 200 OK + token
U->>A: GET /profile
A-->>U: profile dataER diagram example
Entities with attributes and the relationships between them. Have SQL CREATE TABLE statements? The ER Diagram Generator draws the diagram from them.
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ ORDER_ITEM : contains
PRODUCT ||--o{ ORDER_ITEM : "ordered in"
CUSTOMER {
int id
string name
string email
}
ORDER {
int id
date created_at
string status
}
PRODUCT {
int id
string title
decimal price
}Class diagram example
Classes with members and inheritance.
classDiagram
class Animal {
+String name
+int age
+makeSound()
}
class Dog {
+String breed
+bark()
}
class Cat {
+bool indoor
+meow()
}
Animal <|-- Dog
Animal <|-- CatState diagram example
States and the transitions between them.
stateDiagram-v2
[*] --> Idle
Idle --> Loading : fetch()
Loading --> Success : resolve
Loading --> Failure : reject
Success --> Idle : reset()
Failure --> Idle : retry()
Success --> [*]Gantt chart example
Tasks on a timeline, grouped in sections.
gantt
title Project Timeline
dateFormat YYYY-MM-DD
section Design
Wireframes :done, des1, 2026-01-01, 5d
Mockups :active, des2, after des1, 5d
section Build
Frontend : dev1, after des2, 10d
Backend : dev2, after des2, 10d
section Launch
QA : qa1, after dev1, 5d
Release : rel1, after qa1, 2dPie chart example
Shares of a whole.
pie title Browser Market Share
"Chrome" : 65
"Safari" : 18
"Edge" : 8
"Firefox" : 6
"Other" : 3Mindmap example
A tree of ideas around one root.
mindmap
root((Project))
Planning
Requirements
Timeline
Design
Wireframes
Prototypes
Development
Frontend
Backend
Launch
QA
DeployGit graph example
Branches, commits and merges.
gitGraph
commit id: "init"
branch develop
checkout develop
commit id: "feature-a"
commit id: "feature-b"
checkout main
merge develop
commit id: "release-1.0"User journey example
Steps a person takes, scored by how they feel.
journey
title Signing up for an account
section Discover
Visit homepage: 5: User
Read features: 4: User
section Sign up
Fill form: 3: User
Verify email: 2: User
section First use
Complete onboarding: 4: User
Create first project: 5: UserCustomise and export
The editor has four themes and exports SVG, PNG (1x to 3x) and a one-page PDF; see how to export a Mermaid diagram. For the syntax behind these examples, see the Mermaid cheat sheet.
Frequently asked questions
- How do I use these Mermaid examples?
- Copy the code into any Mermaid renderer, or click "Open in editor" to load it into the Hexabench editor, where you can edit and export it.
- What is the difference between graph and flowchart?
- flowchart is the current keyword and supports more features; graph still works for basic charts.
- How do I draw a loop or condition in a sequence diagram?
- Wrap the messages in loop ... end or alt ... else ... end.
- How do I make an ER diagram from SQL tables?
- Write the entities and relationships by hand in Mermaid, or paste CREATE TABLE statements into the ER Diagram Generator, which draws the diagram for you.
- Can I use these in GitHub or Markdown?
- GitHub renders fenced code blocks tagged mermaid in Markdown files. Copy the diagram text between the fences.
- How do I save an example as an image?
- Open it in the editor and use Export PNG, SVG or PDF.
- Do the examples work in other Mermaid tools?
- They are standard Mermaid syntax, so they should render in any recent Mermaid release; rendering details can differ by version.
- Can I share my edited example?
- Yes, use "Copy share link" in the editor. The link contains the whole diagram, so do not use it for confidential diagrams.