Expert guidance for Mermaid.js diagramming library. Create flowcharts, sequence diagrams, class diagrams, state diagrams, Gantt charts, git graphs, and block diagrams...
Expert guidance for Mermaid.js, the powerful JavaScript library for creating diagrams and visualizations using text-based syntax. Mermaid transforms simple text descriptions into professional-looking diagrams that can be embedded in documentation, presentations, and web applications.
For comprehensive documentation and advanced features, see the Mermaid Source Documentation which includes:
For integration details and configuration options, refer to the main documentation at docs/snapshot/v11.12.1/.
Mermaid is a text-to-diagram tool that allows you to create:
Basic Mermaid syntax structure:
diagramType
[diagram content]
Simple flowchart example:
flowchart TD
A[Start] --> B{Decision}
B -->|Yes| C[Process 1]
B -->|No| D[Process 2]
C --> E[End]
D --> E
In HTML:
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
In Markdown/Documentation:
Most modern platforms (GitHub, GitLab, Notion) support Mermaid natively using code blocks with mermaid language identifier.
Node.js/npm:
npm install mermaid
For flowchart diagrams only: mmdr (mermaid-rs-renderer)
mmdr is a fast native Rust renderer for flowchart diagrams only. It is ~1000x faster than mermaid-cli and requires no browser or Node.js.
Check if installed:
mmdr --version
If not found, install from: https://github.com/1jehuang/mermaid-rs-renderer
Usage (flowcharts only):
# Pipe to stdout
echo 'flowchart LR; A-->B-->C' | mmdr -e svg
# File to file
mmdr -i diagram.mmd -o output.svg -e svg
For all other diagram types: mermaid-cli
Check if installed:
mmdc --version
If not found, install from: https://github.com/mermaid-js/mermaid-cli
# Convert to SVG
mmdc -i input.mmd -o output.svg
# Convert to PNG with dark theme
mmdc -i input.mmd -o output.png -t dark -b transparent
# Process markdown files
mmdc -i readme.template.md -o readme.md
flowchart LR
A[Start] --> B[Process]
B --> C{Decision}
C -->|Yes| D[Action 1]
C -->|No| E[Action 2]
D --> F[End]
E --> F
flowchart TD - Top Down directionflowchart LR - Left to Right directionA[Text] - Rectangle nodeA{Text} - Diamond decision nodeA((Text)) - Circle nodeA>Text] - Stadium shapeA --> B - Arrow connectionA -->|Label| B - Labeled arrowsequenceDiagram
participant Alice
participant Bob
Alice->>Bob: Hello Bob, how are you?
Bob-->>Alice: I am good thanks!
Alice->>Bob: See you later!
participant Name - Define participantA->>B: Message - Synchronous messageA-->B: Message - Async message (dashed line)A-->>B: Message - Return messagerect rgb(...) - Group messagesloop / alt / opt - Control structuresclassDiagram
class Animal{
+String name
+eat()
}
class Duck{
+quack()
}
Animal <|-- Duck
class ClassName{ ... } - Define class+Type name - Public member-Type name - Private membermethodName() - MethodChild <|-- Parent - InheritanceA *-- B - CompositionA o-- B - AggregationstateDiagram-v2
[*] --> Idle
Idle --> Processing
Processing --> Success
Processing --> Failed
Success --> [*]
Failed --> [*]
[*] - Start/end stateA --> B - TransitionA: event - Triggered transitionstate A { ... } - Composite state[*] --> A - Initial stategantt
title Project Timeline
dateFormat YYYY-MM-DD
section Phase 1
Design :a1, 2024-01-01, 7d
section Phase 2
Development :a2, after a1, 14d
Testing :a3, after a2, 7d
title Text - Chart titledateFormat YYYY-MM-DD - Date formatsection Name - Section headerTask :id, start, duration - Define taskafter taskId - DependencygitGraph
commit
commit
branch develop
checkout develop
commit
commit
checkout main
merge develop
commit
commit - Create commitbranch name - Create branchcheckout name - Switch branchmerge name - Merge branchcherry-pick id - Cherry-pick commitblock-beta
columns 1
block:db:1
database[(Database)]
end
block:app:2
service[Service]
api[API]
end
db -- API
block:name:width - Define blocknode[(Text)] - Rounded nodenode[Text] - Square nodeA -- B - Connectioncolumns N - Column layoutMost platforms support Mermaid natively:
```mermaid
flowchart LR
A --> B
```
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<div class="mermaid">
flowchart LR
A --> B
</div>
import mermaid from 'mermaid';
mermaid.initialize({ startOnLoad: true });
// Render programmatically
const diagram = await mermaid.render('diagram-id', 'flowchart LR\nA-->B');
Common Issues:
Debug Tips:
See references/ADVANCED.md for advanced features including styling, theming, and complex diagram patterns.