Mermaid Diagrams
A diagram is done when it renders without error and its layout reads clearly.
Pick the type that matches the content (process, messages, schema, schedule,
hierarchy, and so on); a flowchart is not the answer to everything.
Renderer support
- Each host (GitHub, GitLab, a docs site, an IDE preview) bundles its own
Mermaid release, often older than the latest.
-beta keywords (xychart-beta, sankey-beta, architecture-beta,
block-beta) and recent types such as kanban may fail there.
- When the target renderer is unknown, prefer a core type, or ask which
renderer will display the diagram.
Default to a frontmatter config: block before the diagram keyword. Fall back
to a first-line %%{init: {...}}%% directive only for a renderer too old to
read frontmatter config.
Validate by rendering
Write the diagram to <out>/diagram.mmd in a scratch directory and render it:
npx -y @mermaid-js/mermaid-cli@12.0.0 -i <out>/diagram.mmd -o <out>/diagram.png
For a Markdown file, -i doc.md -o <out>/doc.md renders every mermaid block.
Fix each Parse error on line N or Lexical error and render again until it
succeeds. When layout matters, open the PNG and check direction, overlaps, and
label text. Only then put the code in its destination.
If mmdc cannot find Chrome, write
{"executablePath": "<path to an installed Chrome or Chromium>"} to
<out>/puppeteer.json and add -p <out>/puppeteer.json. If Node, network, or
a browser is unavailable, do not install one without asking; check the diagram
against the gotchas below and tell the user it was not rendered.
A successful CLI render uses the Mermaid release bundled with the CLI, so it
does not prove an older host renders the diagram.
Gotchas
Several of these fail silently rather than with a parse error.
- Labels containing
(), [], {}, :, ;, or # are wrapped in
"..."; inner quotes are written #quot;, < and > as #lt; and #gt;.
- A lowercase
end as a flowchart node ID or bare label breaks the parse; use
End or ["end"].
- A node ID beginning with
o or x right after a link (A---oB) silently
becomes a circle or cross edge; add a space or capitalize.
%% comments sit on their own line; a trailing comment is a parse error.
- Block diagrams have no
==> or ::: shorthand.
- Indentation is significant in
mindmap and kanban.
- Styling not applying: the config block must come first,
themeVariables
need theme: base, and hex colors in frontmatter must be quoted (an unquoted
# is a YAML comment and the color is silently dropped).
- Renders in the CLI but not on the host: the host's Mermaid is older; replace
a
-beta or recent type, or switch frontmatter config to %%{init}.
1---2name: drawing-mermaid-diagrams3description: Writes, edits, and debugs Mermaid diagrams (flowchart, sequence, class, state, ER, Gantt, pie, mindmap, timeline, quadrant, git graph, XY, Sankey, architecture, journey, kanban, block). Use when the user says "draw a diagram", or when the user asks for a diagram, flowchart, ERD, or Mermaid code, or when a Mermaid diagram fails to parse or render.4metadata:5 source: https://skillmd.com/skills/bostonaholic/drawing-mermaid-diagrams6---78# Mermaid Diagrams910A diagram is done when it renders without error and its layout reads clearly.11Pick the type that matches the content (process, messages, schema, schedule,12hierarchy, and so on); a `flowchart` is not the answer to everything.1314## Renderer support1516- Each host (GitHub, GitLab, a docs site, an IDE preview) bundles its own17 Mermaid release, often older than the latest.18- `-beta` keywords (`xychart-beta`, `sankey-beta`, `architecture-beta`,19 `block-beta`) and recent types such as `kanban` may fail there.20- When the target renderer is unknown, prefer a core type, or ask which21 renderer will display the diagram.2223Default to a frontmatter `config:` block before the diagram keyword. Fall back24to a first-line `%%{init: {...}}%%` directive only for a renderer too old to25read frontmatter config.2627## Validate by rendering2829Write the diagram to `<out>/diagram.mmd` in a scratch directory and render it:3031```sh32npx -y @mermaid-js/mermaid-cli@12.0.0 -i <out>/diagram.mmd -o <out>/diagram.png33```3435For a Markdown file, `-i doc.md -o <out>/doc.md` renders every mermaid block.36Fix each `Parse error on line N` or `Lexical error` and render again until it37succeeds. When layout matters, open the PNG and check direction, overlaps, and38label text. Only then put the code in its destination.3940If `mmdc` cannot find Chrome, write41`{"executablePath": "<path to an installed Chrome or Chromium>"}` to42`<out>/puppeteer.json` and add `-p <out>/puppeteer.json`. If Node, network, or43a browser is unavailable, do not install one without asking; check the diagram44against the gotchas below and tell the user it was not rendered.4546A successful CLI render uses the Mermaid release bundled with the CLI, so it47does not prove an older host renders the diagram.4849## Gotchas5051Several of these fail silently rather than with a parse error.5253- Labels containing `()`, `[]`, `{}`, `:`, `;`, or `#` are wrapped in54 `"..."`; inner quotes are written `#quot;`, `<` and `>` as `#lt;` and `#gt;`.55- A lowercase `end` as a flowchart node ID or bare label breaks the parse; use56 `End` or `["end"]`.57- A node ID beginning with `o` or `x` right after a link (`A---oB`) silently58 becomes a circle or cross edge; add a space or capitalize.59- `%%` comments sit on their own line; a trailing comment is a parse error.60- Block diagrams have no `==>` or `:::` shorthand.61- Indentation is significant in `mindmap` and `kanban`.62- Styling not applying: the config block must come first, `themeVariables`63 need `theme: base`, and hex colors in frontmatter must be quoted (an unquoted64 `#` is a YAML comment and the color is silently dropped).65- Renders in the CLI but not on the host: the host's Mermaid is older; replace66 a `-beta` or recent type, or switch frontmatter config to `%%{init}`.