All diagram types Open editor

merIDK / Diagram types / State diagram

Mermaid state diagram: example and syntax

State diagrams model something that moves between states, such as an order, a UI component or a network connection, and the events that cause each change.

Open this example in the editor

Example code

stateDiagram-v2
    [*] --> Idle
    Idle --> Running : start
    state Running {
        [*] --> Loading
        Loading --> Ready
        Ready --> Loading : reload
    }
    Running --> check
    state check <<choice>>
    check --> Done : success
    check --> Failed : error
    Failed --> Idle : retry
    Done --> [*]
    note right of Failed : Logged to Sentry

Result

stateDiagram-v2
    [*] --> Idle
    Idle --> Running : start
    state Running {
        [*] --> Loading
        Loading --> Ready
        Ready --> Loading : reload
    }
    Running --> check
    state check <<choice>>
    check --> Done : success
    check --> Failed : error
    Failed --> Idle : retry
    Done --> [*]
    note right of Failed : Logged to Sentry

Syntax quick reference

How to use it

  1. Open the example in the editor, or paste your own Mermaid code.
  2. Edit the code on the left. The preview updates as you type, and errors point to the line.
  3. Export SVG or PNG, copy a Markdown block for GitHub or Notion, or copy a share link.

More diagram types