---
title: "Mermaid syntax cheat sheet: every common diagram, with examples"
description: "Every Mermaid diagram starts with a line that names its type, and the rest follows that type's own rules. This page has the first line and a working example for ten diagram types, the rules shared by all of them, and the mistakes that break a diagram. Each example opens in our free editor."
date: 2026-11-29
lang: en
canonical: https://goingstellar.ro/methods/mermaid-syntax-cheat-sheet/
author: Going Stellar
publisher: GOING STELLAR S.R.L.
topic: Mermaid / Diagrams
license: CC BY 4.0
alternate_ro: https://goingstellar.ro/ro/metode/fituica-sintaxa-mermaid/
---

# Mermaid syntax cheat sheet: every common diagram, with examples

*Every Mermaid diagram starts with a line that names its type, and the rest follows that type's own rules. This page has the first line and a working example for ten diagram types, the rules shared by all of them, and the mistakes that break a diagram. Each example opens in our free editor.*

> Mermaid · Diagrams · 2026-11-29 · https://goingstellar.ro/methods/mermaid-syntax-cheat-sheet/

## Key points

- The first line names the type; only front matter between `---` lines may come before it.
- Misspelled words break a diagram; wrong settings are ignored without an error.
- `%%` starts a comment; Mermaid ignores the rest of the line.
- Quote any text that contains `end` or brackets.

## The rules every diagram shares

The first line names the diagram type, such as `flowchart LR` or `sequenceDiagram`. The only thing allowed before it is front matter between two `---` lines. A line starting with `%%` is a comment.

The Mermaid documentation puts the main trap in one sentence: unknown words and misspellings break a diagram, while wrong parameters fail silently. A typo in the type, such as `flowchat`, gives `No diagram type detected`; a wrong setting is ignored and the diagram draws as if it were not there.

## First lines at a glance

| Diagram | First line | Guide |
|---|---|---|
| Flowchart | `flowchart LR` (or `TD`, `RL`, `BT`) | flowchart |
| Sequence | `sequenceDiagram` | sequence |
| Class | `classDiagram` | below |
| State | `stateDiagram-v2` | below |
| Entity relationship | `erDiagram` | ER |
| Gantt | `gantt` | Gantt |
| Pie | `pie` | below |
| Mind map | `mindmap` | below |
| Timeline | `timeline` | below |
| Git graph | `gitGraph` | below |

## Flowchart

Nodes are an id with a shape: `[ ]` box, `( )` rounded, `{ }` decision, `[( )]` database, `(( ))` circle, `[/ /]` slanted. `--&gt;` is an arrow, `-.-&gt;` a dotted one, and `-- text --&gt;` puts a label on it. `subgraph` … `end` draws a box around nodes.

```mermaid
flowchart LR
    A[Request] --> B{Valid?}
    B -- yes --> C(Process)
    B -- no --> D[/Reject/]
    C --> E[(Database)]
    C -.-> F((Notify))
    subgraph Backend
        C
        E
    end
```

Open this example in the editor (Cheat sheet: flowchart).

## Sequence diagram

`-&gt;&gt;` is a solid message, `--&gt;&gt;` a dotted reply. `+` and `-` after the arrow, or `activate` and `deactivate`, show when a participant is busy. `alt`/`else`, `loop` and `opt` blocks close with `end`. `autonumber` numbers the messages.

```mermaid
sequenceDiagram
    autonumber
    actor U as User
    participant A as App
    participant S as Server
    U->>A: Tap "Pay"
    A->>+S: POST /pay
    alt card accepted
        S-->>A: 200 OK
    else card declined
        S-->>A: 402
    end
    deactivate S
    Note over A,S: Retries are not shown
    loop every 5 s
        A->>S: GET /status
    end
```

Open this example in the editor (Cheat sheet: sequence diagram).

## Class diagram

Members go in braces: `+` public, `-` private, a method ends in `()` and may be followed by a return type. Generics use tildes, `List~Item~`. `*--` is composition, `--&gt;` association, `..|&gt;` realization, and the quoted numbers are the multiplicity.

```mermaid
classDiagram
    class Order {
        +int id
        +Date placedAt
        -List~Item~ items
        +total() decimal
    }
    class Item {
        +String sku
        +int quantity
    }
    class Payment {
        <<interface>>
        +pay(amount) bool
    }
    Order "1" *-- "1..*" Item : contains
    Order --> Payment : uses
    CardPayment ..|> Payment
```

Open this example in the editor (Cheat sheet: class diagram).

## State diagram

`[*]` is the start or the end, depending on the side of the arrow. A label after a colon names the transition. `state Name { }` nests states inside a composite state.

```mermaid
stateDiagram-v2
    [*] --> Draft
    Draft --> Review : submit
    Review --> Draft : changes requested
    Review --> Published : approve
    state Published {
        [*] --> Live
        Live --> Archived : archive
    }
    Published --> [*]
```

Open this example in the editor (Cheat sheet: state diagram).

## Pie, mind map, timeline and git graph

A pie chart takes a title and quoted labels with values; `showData` prints the values in the legend.

```mermaid
pie showData
    title Tickets by channel
    "Email" : 412
    "Chat" : 268
    "Phone" : 97
```

Open this example in the editor (Cheat sheet: pie chart).

A mind map has no arrows: indentation is the structure. `(( ))` makes the root a circle.

```mermaid
mindmap
  root((Launch))
    Product
      Pricing
      Docs
    Marketing
      Blog post
      Newsletter
    Support
      FAQ
```

Open this example in the editor (Cheat sheet: mind map).

A timeline is one period per line, then its events after colons.

```mermaid
timeline
    title Release history
    2026 Q1 : v1.0 public beta
    2026 Q2 : v1.1 dark mode : v1.2 exports
    2026 Q3 : v2.0 teams
```

Open this example in the editor (Cheat sheet: timeline).

A git graph replays git commands: `commit`, `branch`, `checkout`, `merge`. It starts on `main`.

```mermaid
gitGraph
    commit
    branch feature
    checkout feature
    commit
    commit
    checkout main
    merge feature
    commit tag: "v1.0"
```

Open this example in the editor (Cheat sheet: git graph).

## Title, theme and comments

Front matter goes before the first line: `title` adds a heading, and `config` changes settings for this diagram only, such as the theme (`default`, `neutral`, `dark`, `forest`, `base`). The indentation in the front matter matters, because it is YAML.

```mermaid
---
title: Order flow
config:
  theme: forest
---
%% a comment: Mermaid ignores this line
flowchart TD
    A[Cart] --> B[Checkout] --> C[Paid]
```

Open this example in the editor (Cheat sheet: title and config in front matter).

## Words and symbols that break a diagram

**`end` as a node in a flowchart or a sequence diagram.** It closes a block, so this fails with a parse error:

```mermaid
flowchart LR
    A[Start] --> end
```

Put it in quotes and it renders:

```mermaid
flowchart LR
    A[Start] --> B["end"]
```

Open this example in the editor (Cheat sheet: the word end in a flowchart).

**Brackets inside a node's text.** `A[a (b) c]` fails with a parse error, because `(` starts another shape. Quote the text: `A["a (b) c"]`.

## In Confluence

Confluence Cloud does not render Mermaid on its own. Mermaid Studio for Confluence, our app, does: type `/Mermaid` on a page, write or paste the code with a live preview, or start from one of eight templates (flowchart, sequence, Gantt, class, ER, state, pie, mind map). The diagram follows Confluence's light or dark mode, or keeps one of five themes. Copying the SVG is free; Pro adds downloads as PNG or SVG and an AI that writes the Mermaid from a plain-English description. It runs Mermaid 11.17.2, and every example on this page renders there as written.

## Limits

Every example was rendered on 29 November 2026 with Mermaid 12.3.0, the version in our editor, and with 11.17.2, the version in Mermaid Studio, in light and dark themes. Mermaid has more types than this page: C4, architecture, block, Sankey, quadrant, XY chart, requirement and others. Some are still marked beta in the documentation, and a site that runs an older Mermaid may not know them yet.

## Sources

1. [Mermaid documentation: Diagram Syntax](https://mermaid.js.org/intro/syntax-reference.html)
2. [Mermaid documentation: Flowcharts](https://mermaid.js.org/syntax/flowchart.html)
3. [Mermaid documentation: Sequence diagrams](https://mermaid.js.org/syntax/sequenceDiagram.html)
4. [Mermaid documentation: Class diagrams](https://mermaid.js.org/syntax/classDiagram.html)
5. [Mermaid documentation: State diagrams](https://mermaid.js.org/syntax/stateDiagram.html)
6. [Mermaid documentation: Pie chart](https://mermaid.js.org/syntax/pie.html)
7. [Mermaid documentation: Mindmap](https://mermaid.js.org/syntax/mindmap.html)
8. [Mermaid documentation: Timeline](https://mermaid.js.org/syntax/timeline.html)
9. [Mermaid documentation: Gitgraph](https://mermaid.js.org/syntax/gitgraph.html)
10. [Atlassian Marketplace: Mermaid Studio for Confluence (version 3.10.0)](https://marketplace.atlassian.com/apps/1011179388/mermaid-studio-ai-mermaid-diagram-editor)

## Questions and answers

### How do I add a comment in Mermaid?

Start the line with `%%`. Mermaid ignores the rest of the line.

### How do I change the theme of one Mermaid diagram?

Add front matter before the first line: `---`, `config:`, `  theme: forest`, `---`.

### Why does my Mermaid diagram say “No diagram type detected”?

The first line is not a known type, often because of a typo such as `flowchat`, or because there is text before it.

### Is graph the same as flowchart in Mermaid?

Both start a flowchart. `flowchart` is the newer keyword; `graph` still works.

## How to cite

**Cite this as:** Going Stellar (2026). *Mermaid syntax cheat sheet: every common diagram, with examples*. GOING STELLAR S.R.L.. https://goingstellar.ro/methods/mermaid-syntax-cheat-sheet/

```bibtex
@misc{goingstellar2026mermaid,
  title  = {Mermaid syntax cheat sheet: every common diagram, with examples},
  author = {{Going Stellar}},
  year   = {2026},
  url    = {https://goingstellar.ro/methods/mermaid-syntax-cheat-sheet/},
  note   = {2026-11-29}
}
```

Licence. Free to quote with attribution.

## Also available

- This page as HTML: https://goingstellar.ro/methods/mermaid-syntax-cheat-sheet/
- Same article in Romanian: https://goingstellar.ro/ro/metode/fituica-sintaxa-mermaid/
