Mermaid State Diagram Examples
State diagrams show how one thing moves through a lifecycle, such as an order, a ticket, a subscription, or a connection. Each arrow is a transition, and its label is the event that causes it.
Use stateDiagram-v2 for the current renderer. [*] marks the start and end states.
Order lifecycle
A simple linear lifecycle with one cancellation path. Transition labels name the event, which keeps the diagram useful for both engineers and support teams.
Rendering preview…
stateDiagram-v2
[*] --> Pending
Pending --> Paid : payment captured
Pending --> Cancelled : 30 min timeout
Paid --> Shipped : label printed
Shipped --> Delivered : carrier scan
Delivered --> [*]
Cancelled --> [*]Approval workflow with composite state and choice
A state Name { } block nests sub-states, and <<choice>> creates a decision point after the review finishes.
Rendering preview…
stateDiagram-v2
state decision <<choice>>
[*] --> Draft
Draft --> Review : submit
state Review {
[*] --> Legal
Legal --> Editorial
Editorial --> [*]
}
Review --> decision
decision --> Published : approved
decision --> Draft : changes requested
Published --> [*]Circuit breaker with a note
The three states of a circuit breaker, with a note explaining what happens while the circuit is open.
Rendering preview…
stateDiagram-v2
[*] --> Closed
Closed --> Open : failure threshold reached
Open --> HalfOpen : cooldown elapsed
HalfOpen --> Closed : trial request succeeds
HalfOpen --> Open : trial request fails
note right of Open
Requests fail fast
without calling the service
end noteState Diagram syntax cheat sheet
| Syntax | Meaning |
|---|---|
[*] --> A | Start state |
A --> [*] | End state |
A --> B : event | Transition with a label |
state Name { ... } | Composite (nested) state |
state x <<choice>> | Choice (decision) node |
state f <<fork>> / <<join>> | Fork and join for parallel paths |
note right of A ... end note | Multi-line note |
-- | Concurrency separator inside a composite state |
Common state diagram mistakes
- Use
stateDiagram-v2. The olderstateDiagramkeyword still works but uses the previous renderer. - State names cannot contain spaces. Use an ID with a description:
state "Waiting for payment" as Waiting. - Declare a
<<choice>>state before you draw transitions into it.
State Diagram FAQ
When should I use a state diagram instead of a flowchart?
Use a state diagram when the subject is one object that changes status over time. Use a flowchart when you are describing steps or decisions in a process.
How do I show parallel states?
Inside a composite state, separate the parallel regions with a line containing only
--.Keep going
- Why diagram-as-code works for documentation
- Open the free Mermaid editor to write your own diagram with live preview.
More Mermaid examples
- Mermaid flowchart examples
- Mermaid sequence diagram examples
- Mermaid er diagram examples
- Mermaid class diagram examples
- Mermaid gantt chart examples
- Mermaid pie chart examples
- Mermaid mindmap examples
Last updated 2026-11-28.