Flowchart
Start with flowchart and a direction: TD for top down, LR for left to
right. Each node has an id and a label. Arrows join the ids.
You write
```mermaid
flowchart TD
start([Order placed]) --> paid{Paid?}
paid -->|Yes| ship[Ship it]
paid -->|No| remind[Send a reminder]
remind --> paid
```You see
| Write | Shape |
|---|---|
id[Text] | Rectangle |
id(Text) | Rounded rectangle |
id([Text]) | Pill |
id{Text} | Diamond, a decision |
id((Text)) | Circle |
--> is an arrow, --- a plain line, -.-> a dotted arrow, and
-->|label| puts text on the arrow.
Sequence diagram
For messages passed between people or systems, in order.
You write
```mermaid
sequenceDiagram
Browser->>Server: Log in
Server->>Database: Check password
Database-->>Server: OK
Server-->>Browser: Welcome
```You see
->> is a solid arrow, -->> a dashed reply.
Gantt chart
For a plan over time. Each task has a name, an id or a start, and a length.
You write
```mermaid
gantt
dateFormat YYYY-MM-DD
section Build
Design :a1, 2026-01-05, 5d
Code :a2, after a1, 10d
section Ship
Test :after a2, 4d
```You see
Pie chart
You write
```mermaid
pie title Where the time went
"Writing" : 50
"Editing" : 30
"Meetings" : 20
```You see
The numbers do not need to add up to 100. Mermaid works out the shares.
Other diagrams
Mermaid also draws class diagrams, state diagrams, entity relationship
diagrams, mind maps, timelines, user journeys and Git graphs. Each starts with
its own keyword, such as classDiagram or mindmap, and the
Mermaid documentation has the syntax for each.
Where Mermaid renders
| App | Mermaid |
|---|---|
| GitHub | Yes, in files, issues and comments |
| GitLab | Yes |
| MarkdownPaper | Yes |
| Obsidian | Yes |
| VS Code preview | With an extension |
Where Mermaid is not supported, the block shows as code, so the file still reads.
Common problems
- The code shows instead of a diagram. The fence is not marked
mermaid, or the app does not support it. - "Syntax error" instead of a diagram. Often a label with brackets or
quotes in it. Wrap the label in double quotes:
A["Step (1)"]. - A word breaks the diagram.
endis a keyword in flowcharts. Write it with a capital,End, or put it in quotes.
Questions
How do I add a diagram to a Markdown file?
Write the diagram in Mermaid inside a code block marked mermaid. Apps that
support Mermaid show it as a picture.
Does GitHub render Mermaid diagrams?
Yes. A mermaid code block in a README, an issue or a comment shows as a
diagram.
How do I view a Mermaid diagram that an AI wrote?
Paste the whole answer into a Markdown reader that supports Mermaid, such as MarkdownPaper. The diagram is drawn on the page with the rest of the text.
Next
- Math in Markdown, for equations written as text.
- Read what an AI assistant wrote, diagrams included.