Mermaid state diagram syntax: states, transitions and choices with examples
Mermaid stateDiagram-v2 syntax with rendered examples: start and end markers, labelled transitions, direction, fork and join bars, and choice diamonds.
A state diagram models one object's life: the states it can be in, and the events that move it between them. Mermaid's stateDiagram-v2 is the version to use — the older stateDiagram keyword is accepted for compatibility but -v2 is what the current docs document.
Everything on this page is rendered by makesPDF's own Mermaid renderer, so a ```mermaid block produces exactly this in the PDF.
States and transitions
[*] is the start marker and the end marker — the same symbol, told apart by which side of the arrow it sits on. Everything else is a state, declared implicitly the first time it appears:
stateDiagram-v2
[*] --> Draft
Draft --> Review : Submit
Review --> Approved : Approve
Review --> Draft : Request Changes
Approved --> [*]The text after the colon is the transition label. A transition without one is valid too: Draft --> Review.
Long labels
state "Waiting for approval" as Waiting gives a state an id and a separate display label, so a transition can name the id while the diagram shows the sentence:
stateDiagram-v2
state "Waiting for review" as Waiting
[*] --> Waiting
Waiting --> Published : Approve
Waiting --> Draft : Request changes
Published --> [*]Direction
direction LR on its own line after the header lays the diagram out left to right instead of top down — worth it for a long linear flow that otherwise runs down the page:
stateDiagram-v2
direction LR
[*] --> Draft
Draft --> Review : Submit
Review --> Approved : Approve
Approved --> [*]Fork, join and choice
<<fork>> and <<join>> draw the thick bars used for parallel work, and <<choice>> draws the diamond used for a decision that is resolved by the guard. Each is named beside its shape — above it in a left-to-right diagram — so a fork and a join are distinguishable. Transitions out of a choice are labelled with their conditions:
stateDiagram-v2
[*] --> Fork
state Fork <<fork>>
state Join <<join>>
Fork --> Charge
Fork --> Notify
Charge --> Join
Notify --> Join
Join --> Check
state Check <<choice>>
Check --> Done : card ok
Check --> Failed : declined
Done --> [*]
Failed --> [*]Composite states and notes
A state can contain a diagram of its own. state Editing { … } draws a dashed frame around the inner diagram, with its own start marker, and the surrounding transitions connect to the state as a whole:
stateDiagram-v2
[*] --> Editing
state Editing {
[*] --> Typing
Typing --> Validating
}
Editing --> Published
Published --> [*]note right of <state>: … (or note left of) attaches a sticky note beside a state. Long notes wrap to fit:
stateDiagram-v2
[*] --> Queued
Queued --> Sending
note right of Sending: retried 3x
Sending --> SentNot supported in makesPDF yet: state-level styling (
classDef,class) is parsed but not painted.