Mermaid flowchart syntax: a practical cheat sheet

Every part of a Mermaid flowchart in one place: directions, node shapes, arrows and labels, subgraphs, styling, and the mistakes that break a diagram, with examples you can paste.

Updated November 19, 2026 · 4 min read

Mermaid turns a few lines of text into a flowchart. This cheat sheet covers the syntax you will use every day, with a rendered example for each part. Every example works in any Mermaid editor; paste it into Flowgraph Studio to see it with themes and a cleaner layout.

Start a flowchart

Every flowchart starts with the word flowchart and a direction. The direction decides which way the chart grows.

Direction Meaning
TB or TD Top to bottom (the default)
BT Bottom to top
LR Left to right
RL Right to left
flowchart LR
  A[Write code] --> B[Open a pull request] --> C[Merge]

Each line after the first declares nodes, links, or both. A node is an id followed by its text in brackets; after that, you can refer to it by id alone.

Node shapes

The brackets around a node's text choose its shape.

Syntax Shape
A[Text] Rectangle
A(Text) Rounded rectangle
A([Text]) Stadium (pill)
A[[Text]] Subroutine
A[(Text)] Database (cylinder)
A((Text)) Circle
A(((Text))) Double circle
A>Text] Flag
A{Text} Diamond (decision)
A{{Text}} Hexagon
A[/Text/] Parallelogram
A[/Text\] Trapezoid
flowchart LR
  start([Order received]) --> check{In stock?}
  check -->|Yes| pack[Pack the order]
  check -->|No| wait[[Back-order process]]
  pack --> db[(Orders DB)]

If the text contains brackets, quotes or other symbols, wrap it in double quotes: A["Total (incl. tax)"].

Syntax Link
A --> B Arrow
A --- B Line without an arrow
A -.-> B Dotted arrow
A ==> B Thick arrow
A --o B Circle end
A --x B Cross end
A <--> B Arrows both ways
A ~~~ B Invisible link (affects layout only)

Add a label with pipes, A -->|label| B, or inline, A -- label --> B. Adding dashes, as in A ---> B, makes a link longer, which pushes the target further away.

You can chain links and connect several nodes at once:

flowchart LR
  web[Web app] & mobile[Mobile app] -->|HTTPS| api[API] --> db[(Database)]
  api -.->|async| queue[Queue]

Subgraphs

A subgraph draws a box around related nodes: a service boundary, a network, a team. Give it an id and a title, and end it with end. Links can point at a subgraph as a whole.

flowchart LR
  user([Customer]) --> lb[Load balancer]
  subgraph cluster [Kubernetes cluster]
    direction TB
    lb --> app1[App pod 1]
    lb --> app2[App pod 2]
  end
  cluster --> cache[(Redis)]

The direction line inside a subgraph sets its own layout direction.

Define a class once with classDef, then attach it with ::: or a class line. style styles a single node, and linkStyle styles links by their position (counting from 0).

flowchart LR
  classDef risk fill:#fef3f2,stroke:#d92d20,color:#7a271a
  classDef ok fill:#ecfdf3,stroke:#039855,color:#054f31
  deploy[Deploy] --> canary[Canary at 5%]:::ok
  canary --> rollout[Full rollout]:::ok
  canary --> rollback[Roll back]:::risk
  linkStyle 2 stroke:#d92d20,stroke-dasharray:4 3

In Flowgraph Studio you usually don't need any of this: pick a theme and every node, link and group gets a consistent look, with text colors that stay readable.

Comments

Lines starting with %% are comments and are ignored when drawing:

flowchart TD
  %% The happy path
  A --> B

Mistakes that break a flowchart

  • The word end in lowercase. As node text it closes a subgraph early. Write End, END, or A["end"].
  • Ids starting with o or x after a link. A---oB makes a circle-ended link to B. Add a space (A --- oB) or rename the node.
  • Unbalanced brackets or quotes. Every [, ( and { needs its partner. When a label has symbols, quote the whole label.
  • Missing arrow ends. A -- B is incomplete; use A --- B or A --> B.

In Flowgraph Studio the status bar names the line Mermaid couldn't read, and the canvas keeps the last good drawing while you fix it.

Make it presentation-ready

Plain Mermaid gets the structure right; the look is up to you. In Flowgraph Studio the same code gets:

  • Themes that restyle the whole diagram in one click, including light styles made for articles, slides and print.
  • Layout engines (ELK layered, tree, stress or radial, a grid, or Dagre), a direction switch, spacing, and line styles for cleaner charts.
  • Rich nodes with icons, subtitles, badges and a status light, written inside the label, such as API["@icon:aws:lambda **Orders API** | sub:Python | status:healthy"].
  • Manual mode, to drag, resize and connect nodes, move a connection's ends to any side of a node, and move a node's text, while the code updates.
  • Downloads that match the screen: PNG and SVG files keep the diagram's font and line breaks, so they look the same in a document or a slide deck.
  • Templates to start from: dozens of ready-made flowcharts, sequence diagrams and cloud architectures on the Templates page.

Next, see how to draw an AWS architecture diagram with Mermaid using these pieces.

More guides