---
title: "Mermaid flowchart syntax, with examples you can paste"
description: "A Mermaid flowchart starts with <code>flowchart</code> 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."
date: 2026-11-28
lang: en
canonical: https://goingstellar.ro/methods/mermaid-flowchart-syntax-examples/
author: Going Stellar
publisher: GOING STELLAR S.R.L.
topic: Mermaid / Diagrams
license: CC BY 4.0
alternate_ro: https://goingstellar.ro/ro/metode/sintaxa-flowchart-mermaid-exemple/
---

# 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.*

> Mermaid · Diagrams · 2026-11-28 · https://goingstellar.ro/methods/mermaid-flowchart-syntax-examples/

## Key points

- A flowchart starts with `flowchart` plus a direction: TD/TB, BT, LR or RL.
- The brackets around a node's text set its shape; the characters between two ids set the arrow.
- Subgraphs group nodes and end with `end`; `classDef` plus `:::name` styles them.
- Never name a node `end` in lowercase, and leave a space between `---` and an id starting with o or x.

## 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.

```mermaid
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:

```mermaid
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.

```mermaid
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:

```mermaid
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:

```mermaid
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.

```mermaid
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.

```mermaid
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.

```mermaid
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:

```mermaid
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`:

```mermaid
flowchart LR
    dev---ops
```

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

```mermaid
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](https://mermaid.js.org/syntax/flowchart.html)
2. [Mermaid 12.3.0 on npm](https://www.npmjs.com/package/mermaid/v/12.3.0)
3. [Atlassian Marketplace: Mermaid Studio for Confluence](https://marketplace.atlassian.com/apps/1011179388/mermaid-studio-ai-mermaid-diagram-editor)

## 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 --&gt; B` or `A --&gt;|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

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

```bibtex
@misc{goingstellar2026mermaid,
  title  = {Mermaid flowchart syntax, with examples you can paste},
  author = {{Going Stellar}},
  year   = {2026},
  url    = {https://goingstellar.ro/methods/mermaid-flowchart-syntax-examples/},
  note   = {2026-11-28}
}
```

Licence. Free to quote with attribution.

## Also available

- This page as HTML: https://goingstellar.ro/methods/mermaid-flowchart-syntax-examples/
- Same article in Romanian: https://goingstellar.ro/ro/metode/sintaxa-flowchart-mermaid-exemple/
