Mermaid
mermaid fence turns text into flowcharts, sequence diagrams, Gantt charts, class diagrams and state diagrams — rendered locally, theme-aware, diff-friendly.A mermaid fence renders text as a flowchart, sequence diagram, Gantt chart,
class diagram, ER diagram or state diagram. The diagram exists as source: it goes
into Git, it reviews as a diff, and search finds it. Rendering happens in the
reader’s browser with the Mermaid copy the theme ships — no external service is
contacted. Diagrams that need pixel-level control belong in an SVG, used as an
image.
Shortest form
The fence language is mermaid and there is no other switch. Only when the
theme sees such a fence does it add the Mermaid runtime to that page, and ten
diagrams on one page still load it once.
Sequence diagrams
sequenceDiagram describes messages between participants over time, which suits
request paths and load order.
Gantt charts
gantt draws intervals. Below is the five-year community support window of each
PostgreSQL major version, counted from its release date; 1825d is five years.
Class and ER diagrams
classDiagram draws types and relationships, erDiagram entities and
cardinality. Both are common ways to explain a data model.
State diagrams
stateDiagram-v2 draws states and the conditions between them. Below are the
five states an OINK release passes through. They are not interchangeable, and a
green local build is none of them.
Per-diagram title and configuration
The top of a fence body may carry Mermaid’s own YAML header — this is not Hugo
front matter. title gives the diagram a title and config overrides Mermaid
configuration for this diagram alone. A diagram that hard-codes config.theme
no longer follows the site’s colour scheme.
Light and dark
The theme reads the current colour scheme when the page initializes: in dark
mode it uses Mermaid’s dark theme, in light mode the theme the site
configured. Switching the colour scheme redraws the diagrams in place — the
page is not reloaded, and each diagram holds its height while it is redrawn,
so nothing on the page moves under you.
Site-wide defaults go in hugo.yml with lowercase keys; the theme matches them
back to Mermaid’s own casing:
The full key table is in Configuration; for accepted values see the Mermaid configuration reference.
Inside tabs and steps
A mermaid fence has no tab attribute — adjacent-fence tabs apply to ordinary
code fences only. To compare two diagrams side by side, use the tabs
shortcode.
Each step inside {{% steps %}} is page-level Markdown and can hold a
mermaid fence; see Steps.
Output
| Output | Shape |
|---|---|
| HTML | A figure holding an empty stage and the fence source as JSON; the page’s Mermaid runtime draws the SVG into it |
The source inside <pre class="td-mermaid-source">, static — no runtime runs there |
|
| Markdown | The mermaid fence and its source, kept as written |
| RSS | The source inside <pre class="td-mermaid-source"> — subscribers see text |
Parameter reference
Fence attributes: none. A mermaid fence reads no attribute line; writing
{height=…} or {class=…} neither works nor errors. Size follows the diagram
itself and the container width, and the diagram is centred in it.
Site parameters (hugo.yml):
Per-diagram configuration goes in the YAML header at the top of the fence body
(title, config). That is Mermaid syntax, not a theme parameter.
Enlarging a diagram
A diagram is centred in the column, and Mermaid scales anything wider than the
column down to fit — a wide sequence diagram can land near a third of its own
size on a phone. Hovering a diagram (or reaching it with the keyboard) reveals
a control in its corner that opens the diagram on its own: rendered again at
full size, panned by dragging, zoomed with the wheel, a pinch, or the + and
- keys, and reset with 0. Esc closes it. A diagram that would have to
shrink past half size to fit opens at 1:1 at its starting corner instead of as
a thumbnail, and zooming back out always reaches the whole diagram however
large it is. Nothing is downloaded for this and there is no switch to set: the
viewer ships with the fence.
Limits
- Diagrams cannot be numbered: Mermaid emits inline SVG, not an
<img>, so{#id num=}numbering does not apply. Export to an image when you need a number and use the image numbering. - Fence attributes do nothing: control width inside the diagram (flowchart direction, class-diagram layout) or with CSS. There is no alignment attribute — a diagram is always centred.
- Syntax errors show up only in the browser: Hugo does not parse Mermaid, so a broken diagram renders an alert carrying the parse error and its own source, while the build still passes. Check in a browser before publishing.
- RSS, Markdown and Print carry the source, not the picture: put the conclusion in the prose, not only in the diagram.
Related
- PlantUML — more complete UML, at the price of a rendering server
- Markmap — outline-shaped hierarchies
- ECharts — charts with numbers in them
- Images — hand-drawn SVG and numbering