The first line: direction
Every flowchart starts with flowchart (or the older graph) and a direction:
| Code | Direction |
|---|---|
flowchart TD or TB | Top to bottom |
flowchart LR | Left to right |
flowchart BT | Bottom to top |
flowchart RL | Right to left |
Node shapes
A node is an id followed by its text inside brackets. The bracket style picks the shape.
a[Rectangle] a process step
b([Stadium]) start or end
c((Circle)) event or connector
d{Diamond} decision
e{{Hexagon}} preparation
f[(Cylinder)] database
g(Rounded) rounded step
h>Flag] note or flag
If you use an id again without brackets, Mermaid reuses the same node, so define the text once.
Arrows and links
a --> b arrow
a --- b line without an arrow
a -.-> b dotted arrow
a ==> b thick arrow
a -->|yes| b arrow with a label
a -- yes --> b another way to label
a --> b --> c chain several in one line
A complete example
The text behind that picture:
flowchart TD
pr([Pull request opened]) --> ci{Tests pass?}
ci -->|no| fix[Fix the code] --> ci
ci -->|yes| rv{Review approved?}
rv -->|changes asked| fix
rv -->|yes| merge[Merge to main] --> deploy([Deployed])
Common mistakes
| Problem | Cause | Fix |
|---|---|---|
Error near a word like end | Some words are reserved | Use finish or done as the id |
| Text with brackets breaks | Brackets end the label early | Put the label in quotes: a["Step (draft)"] |
| Two boxes with the same text | Different ids | Reuse the same id |
| Very wide chart | Long left to right chains | Switch to TD or split the chart |
Editing Mermaid visually
Writing text is fast, but moving a box by hand is often faster than rewriting it. In Chalkline, open Diagram as text, paste your Mermaid and press Apply. You can then drag shapes, recolour them, switch between sketch and clean, and copy the Mermaid back out. Shapes you moved keep their place when you edit the text again.
Beyond flowcharts
Chalkline also reads Mermaid sequence, class, ER, state, Gantt, timeline and mind map diagrams, plus D2 and PlantUML activity diagrams. See the sequence diagram tutorial and UML class diagram examples.