Mermaid Flowcharts & Sequence Diagrams in Markdown
An excruciatingly detailed guide on how to render Mermaid diagrams directly inside your Markdown documents.
Mermaid is a JavaScript-based diagramming and charting tool that uses text and code to generate visualizations. By wrapping Mermaid syntax inside a standard Markdown fenced code block, you can instantly render complex flowcharts, sequence diagrams, Gantt charts, class diagrams, and more.
How to use Mermaid in Markdown
To render a Mermaid diagram, use a fenced code block with the language identifier mermaid.
|
|
|
1. Flowcharts
Flowcharts are composed of nodes (geometric shapes) and edges (arrows or lines).
Graph Direction
You start by declaring a graph or flowchart and its direction:
TBorTD: Top to bottomBT: Bottom to topRL: Right to leftLR: Left to right
Node Shapes
Different brackets represent different shapes:
id1(This is a rounded rectangle)id2[This is a sharp rectangle]id3{This is a diamond decision}id4((This is a circle))id5>This is an asymmetric shape]id6[/This is a parallelogram/]
Example: Complex Flowchart
|
|
|
2. Sequence Diagrams
Sequence diagrams are perfect for detailing how operations are carried out—what messages are sent and when.
Participants and Actors
You can implicitly define participants or explicitly declare them:
|
|
|
Key Syntax Elements:
->>represents a solid line arrow (sync call).-->>represents a dashed line arrow (async/return).activateanddeactivatecreate the thick vertical bars on the lifelines.altandelsecreate logic loops to show different paths.
3. Gantt Charts
Gantt charts are useful for tracking project schedules.
|
|
|
Next Steps
Mermaid supports rapidly expanding features including State Diagrams, Class Diagrams, Git Graphs, Entity Relationship Diagrams, and Pie Charts. Because it renders instantly in the browser, it is the perfect companion to standard Markdown documentation.