Mermaid’s State Diagram lets you describe state machines in plain text — faster than Visio, more precise than Flowchart for describing entity lifecycles. Ideal for: order status, user lifecycle, approval workflows, protocol states.
Why State Diagram over Flowchart
Flowchart describes a process — what steps happen in what order. State Diagram describes states — what condition an entity is in at any given moment, and under what conditions it transitions to another state.
Use cases:
Order systems: Pending → Paid → Shipped → Delivered (each state is a snapshot of the entity)
Approval flows: Draft → Submitted → Under Review → Approved/Rejected
stateDiagram-v2 [*] --> A A --> B B --> [*] classDef errorState fill:#ff6b6b,stroke:#333 class B errorState
Theme
1 2 3 4 5
%%{init: {'theme': 'dark'}}%% stateDiagram-v2 [*] --> Active Active --> Dormant: sleep Dormant --> Active: wake
Mermaid vs PlantUML State Diagram
Feature
Mermaid stateDiagram-v2
PlantUML State
Nested states
✅ max 3 levels
✅ unlimited
Concurrent states
✅
✅
Entry/exit actions
✅
✅
Choice branches
✅
✅
Visual style
hand-drawn
UML strict
Chinese support
✅
✅
Code readability
high (compact)
medium
Both are functionally equivalent. Choose Mermaid for readability, PlantUML for strict UML compliance.
Common Errors
Error
Cause
Fix
Parse error
State ID has space or special char
Wrap in quotes "Long ID"
Invalid transition
Target state doesn’t exist
Check ID spelling
Too many nested levels
Nesting exceeds 3 levels
Reduce or split
Circular dependency
Loop without exit condition
Add [*] end state
Recap
5 things to remember:
Always use stateDiagram-v2 (plain stateDiagram is incomplete)
[*] is the start/end marker
--> target: event[condition] is the transition syntax
Nested states with state parent { child states } express composite states
|| separates concurrent state regions for parallel independent flows
State diagrams describe entity lifecycle — orders, approvals, users, sessions, devices — use them whenever you need to show what state something is in and what triggers transitions.
Title: Mermaid State Diagram: state machines, transitions, and concurrent states