N
NJHTools

State Diagram Maker

Write states and transitions in Mermaid text and get a state machine diagram with live preview and SVG or PNG export. Free, no signup, and it runs in your browser.

Zoom
100%
Export
Mermaid code18 lines

Tab inserts spaces. Press Esc, then Tab, to move focus out. Autosaved in this browser.

PreviewLoading Mermaid…

Rendering…

Example state diagram code

This is the Mermaid source loaded in the editor above. Copy it into a Markdown file inside a ```mermaid block and GitHub, GitLab, Notion or Obsidian will render it.

stateDiagram-v2
    [*] --> Draft
    Draft --> InReview : submit
    InReview --> Draft : request changes
    InReview --> Approved : approve
    Approved --> Published : publish
    Published --> Archived : archive
    Archived --> [*]

    state InReview {
        [*] --> Waiting
        Waiting --> Reviewing : reviewer assigned
        Reviewing --> [*]
    }

    note right of Approved
        Only editors can publish
    end note

State diagram syntax cheat sheet

SyntaxWhat it does
stateDiagram-v2Start a state diagram (v2 renderer).
[*] --> AStart state. A --> [*] marks an end state.
A --> B : eventTransition from A to B, labelled with the event.
state A { ... }Composite state containing its own sub-states.
state c <<choice>>Choice pseudo-state. Also <<fork>> and <<join>>.
note right of A ... end noteAttach a multi-line note to a state.
--Inside a composite state, separates concurrent regions.

How to make a Mermaid state diagram

  1. 1Start the code with stateDiagram-v2.
  2. 2Mark the start with [*] --> Idle.
  3. 3Add transitions such as Idle --> Loading : fetch.
  4. 4Group nested states and add choice points.
  5. 5Export as SVG or PNG, or copy a share link.

States and transitions

Each line State1 --> State2 : event is a transition with an optional label. [*] stands for the start state when it is on the left and the end state when it is on the right.

Give a state a longer description with state "Waiting for payment" as Waiting, then use the short ID in transitions.

Composite states, choices and forks

Nest states with state Active { [*] --> Running ... }. The inner diagram has its own start and end.

Declare a branch point with state check <<choice>> and draw guarded transitions out of it. <<fork>> and <<join>> split and merge parallel flows, and -- inside a composite state separates concurrent regions.

Notes and direction

Add note right of Loading : Times out after 30s to explain a state. Notes can also go left of a state.

Add direction LR on its own line to lay the diagram out left to right, which often suits long linear workflows.

Frequently Asked Questions

Should I use stateDiagram or stateDiagram-v2?↓

Use stateDiagram-v2. It is the newer renderer and supports the current feature set; the older keyword is kept for compatibility.

How do I mark the start and end state?↓

Use [*]. [*] --> First marks the initial state and Last --> [*] marks a final state.

How do I show a conditional branch?↓

Declare state decision <<choice>>, then draw transitions from decision to each target with a label for each condition.

Will this diagram render on GitHub, GitLab or Notion?↓

Yes, all three render Mermaid. On GitHub and GitLab, put the code in a fenced code block that starts with ```mermaid. In Notion, add a code block and set its language to Mermaid. Hosted platforms may run an older Mermaid version, so very new syntax can fail there.

How do I export the diagram as PNG or SVG?↓

Use the export buttons above the preview. SVG stays sharp at any size and suits docs and slides; PNG is a raster image that works anywhere images are accepted. Both are created in your browser.

How does sharing work, and is my diagram private?↓

The share link stores your diagram code in the URL hash, the part after #, which browsers do not send to servers. Nothing is uploaded, and your work is autosaved in your own browser. Anyone with the link can see the diagram, so share it only with people you trust.

Last updated: