LLMs generally know Mermaid syntax well. This file covers only common mistakes and non-obvious behavior.
Node IDs can't have spaces. Labels with special chars need quotes:
flowchart TD
A["Label with: colons"]
B["Label with (parens)"]
Every alt, opt, loop, par, critical, and subgraph block needs end:
sequenceDiagram
alt Success
A->>B: OK
else Failure
A->>C: Error
end
The symbols are non-obvious and easy to mix up:
||--|| Exactly one to exactly one
||--o{ One to zero-or-more
||--|{ One to one-or-more
}o--o{ Zero-or-more to zero-or-more
The o means "zero" (optional), | means "one" (required), { means "many".
Use ~T~ not <T> — angle brackets break the parser:
classDiagram
class List~T~ {
+add(T item)
+get(int index) T
}
TD and TB are identical (top-down). LR works better for sequential/timeline flows.
+ and - on arrows control activation bars:
sequenceDiagram
A->>+B: Request (activates B)
B-->>-A: Response (deactivates B)
Goes BEFORE the diagram type declaration:
%%{init: {'theme':'forest'}}%%
flowchart TD
A --> B