Home / Examples / State Diagram

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.

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.

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.

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 note

State Diagram syntax cheat sheet

SyntaxMeaning
[*] --> AStart state
A --> [*]End state
A --> B : eventTransition 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 noteMulti-line note
--Concurrency separator inside a composite state

Common state diagram mistakes

  • Use stateDiagram-v2. The older stateDiagram keyword 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

More Mermaid examples

Last updated 2026-11-28.