Reference
Mermaid Syntax Guide — Complete Reference
Everything you need to write Mermaid diagrams. From basic syntax rules to advanced configuration options — a single reference page for all diagram types.
Supported Diagram Types
Mermaid supports 10+ diagram types. Declare the type at the start of your code:
graphFlowchart — nodes and edgesflowchartAlias for graph (recommended)sequenceDiagramSequence diagram — actors and messagespiePie chart — data visualizationclassDiagramClass diagram — UML class structurestateDiagramState diagram — finite state machineentityRelationshipDiagramER diagram — database entitiesganttGantt chart — project timelinegitGraphGit graph — repository commitsrequirementDiagramRequirement diagram — system requirementsFlowchart Direction
Control how nodes are arranged and connected:
Syntax
graph TD # Top to Down (default) graph TB # Top to Bottom graph BT # Bottom to Top graph LR # Left to Right graph RL # Right to Left flowchart TD # "flowchart" keyword also works
Node Shapes
The shape of a node determines its semantic meaning:
A[Text]RectangleProcess / ActionA(Text)RoundedRoutine / SubroutineA((Text))CircleStart / End pointA{Text}DiamondDecision / ConditionA[[Text]]SubroutineFunction / MethodA[(Text)]CylinderDatabaseA{{Text}}HexagonPreparation / Alternate processA[/Text/]Trapezoid (right)Manual operationA[\Text\]Trapezoid (left)Manual operationA[(Text)]Circle (alt)Start / End markerArrows & Links
Connect nodes with different line and arrow styles:
Syntax
A --> B "Solid arrow" A --- B "Plain line (no arrow)" A -.-> B "Dotted arrow" A -. - B "Dotted line (no arrow)" A ==> B "Thick arrow" A ==>= B "Extra thick arrow" A -->|text| B "Arrow with label" A o--o B "Open circle ends" A *--* B "Diamond ends" A --o B "One circle end" A --* B "One diamond end" A x-- B "Cross end" subgraph A "Group nodes in container" B --> C end
Node IDs & Labels
Syntax
# ID equals label
graph TD
A --> B
# ID different from label
graph TD
A[Start] --> B[End]
step1[Validate input] --> step2[Process data]
# Multi-word labels (no quotes needed)
graph TD
Start --> Middle[Wait for response]
Middle --> EndThemes
Change the visual style of your diagrams:
Syntax
%%{init: {'theme':'base'}}%%
%%{init: {'theme':'dark'}}%%
%%{init: {'theme':'forest'}}%%
%%{init: {'theme':'neutral'}}%%
%%{init: {'theme':'night'}}%%
%%{init: {'theme':'default'}}%%
%% Custom theme variables %%
%%{init: {'theme': 'base', 'themeVariables': {'primaryColor': '#cdb4db'}}}%%Comments
Syntax
%% Single-line comment
%%
%% This entire line is a comment
graph TD
A --> B %% inline comment (ignored) Common Pitfalls
❌ Special characters in labels
→ Use double quotes: A["Hello & Goodbye"] --> B
❌ Very long node labels
→ Keep labels under 40 chars. Long text wraps awkwardly in small nodes.
❌ Arrow labels with pipes
→ Use |label|: A -->|yes| B or A --> B|: label}
❌ Duplicate node IDs
→ Each ID must be unique. Use descriptive IDs: loginBtn instead of btn1.
❌ HTML entities not rendered
→ Mermaid does not support HTML in labels. Stick to plain text and Unicode symbols.
❌ Diagrams too wide
→ Use graph LR instead of graph TD for wide flows, or use subgraphs to group.
Quick Examples by Type
Flowchart
graph TD
A[Start] --> B{Is it broken?}
B -->|Yes| C[Fix it]
B -->|No| D[Good to go]
C --> DSequence Diagram
sequenceDiagram
User->>API: POST /submit
activate API
API-->>User: 200 OK
deactivate APIPie Chart
pie title Traffic Sources
"Search" : 450
"Social" : 280
"Direct" : 170Try Mermaid syntax now
No signup required. Open mermaid.bkkdev.io and start experimenting.
Open Mermaid Viewer →