elefcode

Mermaid diagram

State Diagram — free online editor

Mermaid state diagrams visualize finite-state machines — perfect for UI states, workflow engines, and protocol design.

What is a Mermaid state diagram?

State diagrams (also called state charts) show all the states a system can be in and the transitions between them. Mermaid supports labelled transitions, nested composite states, fork/join nodes, and start/end markers via `[*]`.

When to use it

  • Document a UI component's loading/error/success states
  • Design a workflow or approval flow
  • Model a protocol or game state
  • Communicate state behaviour in a code review

Syntax in one paragraph

Use `stateDiagram-v2` for the modern syntax. `[*] --> Idle` marks an entry, `Idle --> Active : trigger` is a labelled transition, and nested states go inside `state Outer { … }`.

Example: Fetch lifecycle with retry

stateDiagram-v2
    [*] --> Idle
    Idle    --> Loading : fetch()
    Loading --> Success : data received
    Loading --> Error   : request failed
    Success --> Idle    : reset()
    Error   --> Loading : retry()
    Error   --> Idle    : dismiss()
    Success --> [*]     : unmount

More Mermaid diagrams