Skip to content
Mernyx
Open menu

Mermaid State Diagram Cheat Sheet

States, the moves between them, and the branching in between.

Every picture on this page was drawn byMernyx, the native Mermaid editor for macOS. Not by a browser running Mermaid.js — the same renderer the app uses for its canvas.

States and transitions

A transition is an arrow. A colon after the arrow is the event that causes it.

stateDiagram-v2
  [*] --> Idle
  Idle --> Running : start
  Running --> Idle : stop
A state machine with a start point flowing to Idle, then to Running when started, and back to Idle when stopped.Expand diagram

Start and end

The same [*] marker does both: the arrow into it is the end, the arrow out of it is the start.

stateDiagram-v2
  [*] --> Draft
  Draft --> Published
  Published --> [*]
A start point, then a box labelled Draft, then a box labelled Published, then an end point.Expand diagram

A choice point

A diamond that asks a question. Each outgoing arrow is one answer.

stateDiagram-v2
  [*] --> Check
  Check --> Decide <<choice>>
  Decide --> Accepted : if valid
  Decide --> Rejected : if invalid
A start point leading to a box labelled Check, then to a diamond labelled Decide, which splits into Accepted and Rejected.Expand diagram

A state inside a state

Curly braces open a composite state. Its internal states live inside.

stateDiagram-v2
  [*] --> Active
  state Active {
    [*] --> NumLockOff
    NumLockOff --> NumLockOn : press
    NumLockOn --> NumLockOff : press
  }
  Active --> [*]
A state box named Active containing two smaller states, NumLockOff and NumLockOn, connected by a labelled arrow.Expand diagram

Fork and join

A fork splits the flow, a join waits for every branch to arrive.

stateDiagram-v2
  [*] --> Split <<fork>>
  Split --> A
  Split --> B
  A --> Merge <<join>>
  B --> Merge
  Merge --> [*]
A start point leading to a horizontal bar that splits into two branches, which both lead to a second horizontal bar and then to an end point.Expand diagram

Notes

A note attaches to one state, or floats over two.

stateDiagram-v2
  [*] --> Draft
  Draft --> Review
  note right of Draft
    Still editable
  end note
A state machine with a note box attached to the right of the Draft state.Expand diagram

Direction

The same keyword as flowcharts. Default is top to bottom.

stateDiagram-v2
  direction LR
  [*] --> Idle
  Idle --> Running : start
A start point, an Idle box and a Running box laid out left to right.Expand diagram

Draw it in Mernyx.

Open a .mmd file, move a node on the canvas, and the source comes with it. Native on macOS, no browser involved.

Diagram preview