Going Stellar

Home/Methods

Mermaid · Diagrams

Mermaid flowchart syntax, with examples you can paste

A Mermaid flowchart starts with flowchart and a direction, then lists nodes and links: the brackets around a node's text set its shape, the characters between two nodes set the arrow. Every example below renders as written in Mermaid 12.3, including the two mistakes that break most first diagrams.

Updated

The first line: type and direction

Every flowchart starts with the word flowchart (the older graph also works) followed by a direction: TD or TB for top to bottom, BT for bottom to top, LR for left to right and RL for right to left. After that, each line declares nodes, links or both.

flowchart LR
    A[Start] --> B[Finish]

A node is an id followed by its text in brackets. The id (A, B) is what links refer to; the text is what the reader sees. Declare a node's text once, and use the bare id afterwards.

Node shapes

The brackets around the text choose the shape. These ten cover most diagrams:

flowchart TD
    A[Rectangle] --> B(Rounded)
    B --> C([Stadium])
    C --> D[[Subroutine]]
    D --> E[(Database)]
    E --> F((Circle))
    F --> G{Decision}
    G --> H{{Hexagon}}
    H --> I[/Parallelogram/]
    I --> J>Flag]

Newer Mermaid versions also accept a general form, id@{ shape: name, label: "text" }, which names the shape instead of encoding it in brackets and unlocks more of them (documents, cylinders, notched rectangles and others). The full list is in the Mermaid flowchart documentation.

flowchart LR
    A@{ shape: doc, label: "Monthly report" } --> B@{ shape: cyl, label: "Archive" }

Use one form per diagram where you can: mixing them works, but the bracket form is easier to read in a page's source.

Arrows and labels

The characters between two node ids choose the link:

flowchart LR
    A --> B
    A --- C
    A -.-> D
    A ==> E
    A -- label --> F
    A -->|label| G
    A --o H
    A --x I
    J <--> K
    L ---> M

In order: an arrow, an open line, a dotted arrow, a thick arrow, two ways of putting text on an arrow, a circle end, a cross end, an arrow at both ends, and a longer link. Each extra dash makes a link span one more rank, which is the tool for pushing a node further down without adding invisible nodes.

The & operator links several nodes in one line. This draws A to B and C, and both of them to D:

flowchart LR
    A --> B & C --> D

Subgraphs

A subgraph draws a labelled box around a group of nodes and ends with end. The id before the brackets lets you link to the whole group; a direction line inside sets that group's own layout.

flowchart TB
    subgraph web [Web]
        direction LR
        A[Browser] --> B[CDN]
    end
    subgraph app [Application]
        C[API] --> D[(Database)]
    end
    B --> C

Links between nodes in different subgraphs work as usual. When a subgraph's own direction seems ignored, the usual cause is a link from outside straight to a node inside it: Mermaid then lays the group out with the parent's direction, as the documentation notes.

Colours and styles

classDef defines a reusable style and :::name applies it to a node; style styles a single node. Values are CSS-like properties separated by commas.

flowchart LR
    A[Paid]:::ok --> B[Shipped]
    classDef ok fill:#d1fae5,stroke:#059669
    style B stroke-width:3px

Keep colours in classDef lines at the end of the diagram, so the structure stays readable and a theme change means editing two lines, not twenty.

Text with special characters

Put the text in double quotes when it contains brackets, parentheses or other characters Mermaid would read as syntax. Inside quotes, #quot; writes a double quote. Lines starting with %% are comments.

flowchart LR
    %% a comment line
    A["Price (EUR) [net]"] --> B["Ship #quot;today#quot;"]

The two mistakes that break most first flowcharts

A node called end. In lowercase, end is the keyword that closes a subgraph, so this fails with a parse error:

flowchart LR
    A --> end

Write End, END or give the node a different id with the word in its text: X[end].

A node id that starts with o or x right after a link. Mermaid reads ---o and ---x as circle and cross ends. Here the link gets a circle end and the second node is called ps, not ops:

flowchart LR
    dev---ops

A space after the link fixes it, as does a capital letter:

flowchart LR
    dev--- ops

Try it, then put it where your team reads it

Every example on this page can be pasted into our free online Mermaid editor, which renders it as you type and exports SVG or PNG. It runs in the browser; the diagram text is not uploaded.

If the diagram belongs on a Confluence page, Mermaid Studio for Confluence renders the same syntax on the page itself, so the next edit is a text change rather than a new screenshot. It is free for up to 10 users. Confluence Cloud does not render Mermaid on its own.

Limits

Every example was rendered with Mermaid 12.3.0, the version our editor uses, on 28 November 2026. Other tools may run older Mermaid versions; the @{ shape: … } form in particular needs a recent one. If an example fails elsewhere, check which version that tool uses.

Sources

  1. Mermaid documentation: Flowcharts syntax
  2. Mermaid 12.3.0 on npm
  3. Atlassian Marketplace: Mermaid Studio for Confluence

Questions and answers

What is the difference between graph and flowchart in Mermaid?

Both start a flowchart. flowchart is the newer keyword and the one the Mermaid documentation uses; graph still works.

How do I add text to an arrow in Mermaid?

Either A -- text --> B or A -->|text| B. Both render the text on the arrow.

Why does my Mermaid flowchart fail with a parse error on end?

Lowercase end closes a subgraph, so it cannot be a node id. Use End or another id with the word in its text.

How do I change the direction of a Mermaid flowchart?

Change the direction after flowchart: TD, BT, LR or RL. A subgraph can set its own with a direction line.

How to cite this

Going Stellar (2026). Mermaid flowchart syntax, with examples you can paste. GOING STELLAR S.R.L..
https://goingstellar.ro/methods/mermaid-flowchart-syntax-examples/

Read as Markdown

All methods

Contact

Tell us what is not working

Write in English or Romanian. A person reads it — usually the same person who would do the work — and answers within one business day.