Example
flowchart TD
A[User] -->|Paste Mermaid code| B(MermanDraw)
B --> C{Render}
C -->|Beautiful| D[Diagram]
C -->|Share| E[Link]
E -->|Viral| A Syntax
Direction
flowchart LR
A --> B --> C TD/TB (top-down), LR (left-right), BT, and RL. LR usually fits wide screens and README columns better than TD once a diagram has more than five or six ranks.
Try this snippet →Node shapes
flowchart TD
A[Rectangle]
B(Rounded)
C([Stadium])
D[[Subroutine]]
E[(Database)]
F((Circle))
G{Decision}
H{{Hexagon}}
I[/Parallelogram/]
J[\Trapezoid/] Mermaid 11 adds a general form: K@{ shape: cyl, label: "Queue" } with dozens of named shapes (doc, cyl, hex, delay, and more).
Arrows and edge labels
flowchart LR
A --> B
B --- C
C -.-> D
D ==> E
E -->|label| F
F -- text --> G
G --o H
H --x I Solid, open, dotted, and thick links; circle and cross endings. |label| after the arrow and -- text --> are equivalent ways to label an edge.
Subgraphs
flowchart TB
subgraph Client
UI --> State
end
subgraph Server
API --> DB[(Postgres)]
end
State --> API Subgraphs group nodes with a labelled box. Give a subgraph an ID and a title with subgraph id [Title] when you need to connect to the group itself.
Styling
flowchart LR
A[Start] --> B[Done]
classDef ok fill:#d1fae5,stroke:#059669,color:#064e3b
class B ok
style A stroke-width:2px Inline style for one node, classDef + class for many. In MermanDraw you rarely need this: the theme picker restyles every node at once.
Common mistakes
These are the parse errors that come up most, including in code written by ChatGPT and Claude. Paste any failing diagram into the editor and it marks the offending line.
-
Parentheses, brackets, or quotes inside a label:
A[Click (here)]fails because(opens a new shape.Fix: Quote the label:
A["Click (here)"]. Quoted labels accept any character, including#,;, and markdown. -
Using
endas a node ID (start --> end).endcloses subgraphs and is reserved.Fix: Rename it (
finish,done) or capitalise it (End). Also avoidgraph,subgraph,style, andclickas IDs. -
Single-dash arrows (
A -> B). That is sequence-diagram syntax; flowcharts need two dashes.Fix: Use
-->. AI models mix these up when they have just produced a sequence diagram in the same conversation. -
Literal
\ninside a label to force a line break.Fix: Use
<br/>:A["Line one<br/>Line two"]. Mermaid treats labels as HTML-ish text, not as escaped strings. -
Linking two labelled nodes with the label repeated each time (
A[User] --> B[API]and laterA[User] --> C[DB]).Fix: That works but is noisy. Declare each node once, then connect by ID:
A --> C. If the label text differs between declarations, the last one wins.
Real-world examples
Complete, copy-ready flowcharts for common situations. Each one opens in the editor with a click.
-
Microservices Architecture Flowchart in Mermaid
Mermaid flowchart of a microservices system: web and mobile clients, an API gateway, three services with their own databases, and a message broker.
-
Event-Driven Architecture Flowchart with a Dead-Letter Queue
Mermaid flowchart of an event-driven system: producers publish to topics on an event bus, consumers subscribe, and failed messages go to a dead-letter queue.
-
REST API Request Flowchart: Rate Limit, Auth, Validation
Mermaid flowchart of a REST API middleware chain: rate limiting, authentication, authorization, schema validation, the handler, and every status code returned.
-
Password Reset Flowchart with Token Expiry
Mermaid flowchart of a secure password reset: same response whether the account exists, a 30-minute single-use token, policy checks, and session invalidation.
-
CI/CD Pipeline Flowchart: Commit to Production
A Mermaid flowchart of a CI/CD pipeline: commit, lint and test, build, staging deploy, manual approval, production release, and failure paths back.
-
Blue-Green Deployment Flowchart with Rollback Path
A Mermaid flowchart of a blue-green deployment: live traffic on blue, a new release on green, a health check gate, the router switch, and a rollback path.
-
Kubernetes Deployment Flowchart: Ingress to Pods
A Mermaid flowchart of a Kubernetes workload in one namespace: ingress, service, a deployment with three pods, plus the ConfigMap, Secret, and volume it mounts.
-
Incident Response Flowchart: Alert to Postmortem
A Mermaid flowchart of an on-call incident process: alert, severity triage, mitigation, status page updates, resolution, and a postmortem for SEV1 and SEV2.
-
ETL Pipeline Flowchart: Sources to Data Warehouse
A Mermaid flowchart of an ETL pipeline: databases, event logs, and CSV files pass through extraction, staging, validation, and transformation to a warehouse.
-
Order Fulfillment Process Flowchart for E-commerce
A Mermaid flowchart of an e-commerce order from checkout to delivery: payment authorization, stock check, backorder loop, pick and pack, shipping, and refunds.
-
Purchase Approval Workflow Flowchart with Swimlanes
A Mermaid flowchart that uses subgraphs as swimlanes for requester, manager, and finance, with amount thresholds deciding who signs off on a purchase request.
-
User Sign-up Flowchart with Email and Social Login
A Mermaid flowchart of account creation with two entry paths, email with verification and social login with consent, converging on profile setup.
FAQ
What is the difference between `graph` and `flowchart`?
graph TD is the original keyword and still renders. flowchart TD is the current grammar and is the only one that gets new features such as @{ shape } definitions and markdown labels. Use flowchart for anything new.
How do I control spacing between nodes?
Mermaid exposes nodeSpacing and rankSpacing in its config, but not as part of the diagram text. MermanDraw adds a Layout panel in the editor so you can drag two sliders and see the result live, then export the SVG or PNG with that spacing baked in.
Can I make a node a link?
Yes: click A "https://example.com" "Tooltip". GitHub strips click handlers for security, so links only work in environments where you control the renderer.