Mermaid · Diagrams
Mermaid syntax cheat sheet: every common diagram, with examples
Every Mermaid diagram starts with a line that names its type, and the rest follows that type's own rules. This page has the first line and a working example for ten diagram types, the rules shared by all of them, and the mistakes that break a diagram. Each example opens in our free editor.
Updated
The rules every diagram shares
The first line names the diagram type, such as flowchart LR or sequenceDiagram. The only thing allowed before it is front matter between two --- lines. A line starting with %% is a comment.
The Mermaid documentation puts the main trap in one sentence: unknown words and misspellings break a diagram, while wrong parameters fail silently. A typo in the type, such as flowchat, gives No diagram type detected; a wrong setting is ignored and the diagram draws as if it were not there.
First lines at a glance
| Diagram | First line | Guide |
|---|---|---|
| Flowchart | flowchart LR (or TD, RL, BT) | flowchart |
| Sequence | sequenceDiagram | sequence |
| Class | classDiagram | below |
| State | stateDiagram-v2 | below |
| Entity relationship | erDiagram | ER |
| Gantt | gantt | Gantt |
| Pie | pie | below |
| Mind map | mindmap | below |
| Timeline | timeline | below |
| Git graph | gitGraph | below |
Flowchart
Nodes are an id with a shape: [ ] box, ( ) rounded, { } decision, [( )] database, (( )) circle, [/ /] slanted. --> is an arrow, -.-> a dotted one, and -- text --> puts a label on it. subgraph … end draws a box around nodes.
flowchart LR
A[Request] --> B{Valid?}
B -- yes --> C(Process)
B -- no --> D[/Reject/]
C --> E[(Database)]
C -.-> F((Notify))
subgraph Backend
C
E
end
Open this example in the editor (Cheat sheet: flowchart).
Sequence diagram
->> is a solid message, -->> a dotted reply. + and - after the arrow, or activate and deactivate, show when a participant is busy. alt/else, loop and opt blocks close with end. autonumber numbers the messages.
sequenceDiagram
autonumber
actor U as User
participant A as App
participant S as Server
U->>A: Tap "Pay"
A->>+S: POST /pay
alt card accepted
S-->>A: 200 OK
else card declined
S-->>A: 402
end
deactivate S
Note over A,S: Retries are not shown
loop every 5 s
A->>S: GET /status
end
Open this example in the editor (Cheat sheet: sequence diagram).
Class diagram
Members go in braces: + public, - private, a method ends in () and may be followed by a return type. Generics use tildes, List~Item~. *-- is composition, --> association, ..|> realization, and the quoted numbers are the multiplicity.
classDiagram
class Order {
+int id
+Date placedAt
-List~Item~ items
+total() decimal
}
class Item {
+String sku
+int quantity
}
class Payment {
<<interface>>
+pay(amount) bool
}
Order "1" *-- "1..*" Item : contains
Order --> Payment : uses
CardPayment ..|> Payment
Open this example in the editor (Cheat sheet: class diagram).
State diagram
[*] is the start or the end, depending on the side of the arrow. A label after a colon names the transition. state Name { } nests states inside a composite state.
stateDiagram-v2
[*] --> Draft
Draft --> Review : submit
Review --> Draft : changes requested
Review --> Published : approve
state Published {
[*] --> Live
Live --> Archived : archive
}
Published --> [*]
Open this example in the editor (Cheat sheet: state diagram).
Pie, mind map, timeline and git graph
A pie chart takes a title and quoted labels with values; showData prints the values in the legend.
pie showData
title Tickets by channel
"Email" : 412
"Chat" : 268
"Phone" : 97
Open this example in the editor (Cheat sheet: pie chart).
A mind map has no arrows: indentation is the structure. (( )) makes the root a circle.
mindmap
root((Launch))
Product
Pricing
Docs
Marketing
Blog post
Newsletter
Support
FAQ
Open this example in the editor (Cheat sheet: mind map).
A timeline is one period per line, then its events after colons.
timeline
title Release history
2026 Q1 : v1.0 public beta
2026 Q2 : v1.1 dark mode : v1.2 exports
2026 Q3 : v2.0 teams
Open this example in the editor (Cheat sheet: timeline).
A git graph replays git commands: commit, branch, checkout, merge. It starts on main.
gitGraph
commit
branch feature
checkout feature
commit
commit
checkout main
merge feature
commit tag: "v1.0"
Open this example in the editor (Cheat sheet: git graph).
Title, theme and comments
Front matter goes before the first line: title adds a heading, and config changes settings for this diagram only, such as the theme (default, neutral, dark, forest, base). The indentation in the front matter matters, because it is YAML.
---
title: Order flow
config:
theme: forest
---
%% a comment: Mermaid ignores this line
flowchart TD
A[Cart] --> B[Checkout] --> C[Paid]
Open this example in the editor (Cheat sheet: title and config in front matter).
Words and symbols that break a diagram
end as a node in a flowchart or a sequence diagram. It closes a block, so this fails with a parse error:
flowchart LR
A[Start] --> end
Put it in quotes and it renders:
flowchart LR
A[Start] --> B["end"]
Open this example in the editor (Cheat sheet: the word end in a flowchart).
Brackets inside a node's text. A[a (b) c] fails with a parse error, because ( starts another shape. Quote the text: A["a (b) c"].
In Confluence
Confluence Cloud does not render Mermaid on its own. Mermaid Studio for Confluence, our app, does: type /Mermaid on a page, write or paste the code with a live preview, or start from one of eight templates (flowchart, sequence, Gantt, class, ER, state, pie, mind map). The diagram follows Confluence's light or dark mode, or keeps one of five themes. Copying the SVG is free; Pro adds downloads as PNG or SVG and an AI that writes the Mermaid from a plain-English description. It runs Mermaid 11.17.2, and every example on this page renders there as written.
Limits
Every example was rendered on 29 November 2026 with Mermaid 12.3.0, the version in our editor, and with 11.17.2, the version in Mermaid Studio, in light and dark themes. Mermaid has more types than this page: C4, architecture, block, Sankey, quadrant, XY chart, requirement and others. Some are still marked beta in the documentation, and a site that runs an older Mermaid may not know them yet.
Sources
- Mermaid documentation: Diagram Syntax
- Mermaid documentation: Flowcharts
- Mermaid documentation: Sequence diagrams
- Mermaid documentation: Class diagrams
- Mermaid documentation: State diagrams
- Mermaid documentation: Pie chart
- Mermaid documentation: Mindmap
- Mermaid documentation: Timeline
- Mermaid documentation: Gitgraph
- Atlassian Marketplace: Mermaid Studio for Confluence (version 3.10.0)
Questions and answers
How do I add a comment in Mermaid?
Start the line with %%. Mermaid ignores the rest of the line.
How do I change the theme of one Mermaid diagram?
Add front matter before the first line: ---, config:, theme: forest, ---.
Why does my Mermaid diagram say “No diagram type detected”?
The first line is not a known type, often because of a typo such as flowchat, or because there is text before it.
Is graph the same as flowchart in Mermaid?
Both start a flowchart. flowchart is the newer keyword; graph still works.
How to cite this
Going Stellar (2026). Mermaid syntax cheat sheet: every common diagram, with examples. GOING STELLAR S.R.L..
https://goingstellar.ro/methods/mermaid-syntax-cheat-sheet/