State Diagram Online Editor

Draw state diagrams and state machines with Mermaid online: transitions, composite states, choices, forks and notes, with live preview and free export.

Try it

Edit the code; the preview updates as you type.

Open in editor

Rendering diagram…

What is a state diagram?

A state diagram describes a state machine: the states something can be in, the events that move it from one state to another, and where it starts and ends.

In Mermaid you write stateDiagram-v2 and then one transition per line. [*] marks the start and end points, and nested blocks describe composite states.

When to use it

  • Order, ticket or document lifecycles
  • UI component states such as loading, error and success
  • Protocol and connection handling
  • Game logic and device modes
  • Workflow approvals with rejections and retries

Mermaid state diagram syntax

Every diagram of this type starts with stateDiagram-v2.

SyntaxMeaning
[*] --> AStart state. A --> [*] is an end state.
A --> B : eventA transition with an optional label after the colon.
state "Long name" as LA state whose label contains spaces.
state A { ... }A composite state with its own inner states.
state c <<choice>>A decision point with several outgoing transitions.
<<fork>> / <<join>>Split into parallel paths and merge them again.
--Separates concurrent regions inside a composite state.
note right of AA note next to a state; end it with end note.
direction LRLays the diagram out left to right.

More examples

Choice state

Rendering diagram…
Mermaid code
stateDiagram-v2
  state check <<choice>>
  [*] --> Payment
  Payment --> check
  check --> Paid : card accepted
  check --> Failed : card declined
  Failed --> Payment : retry
  Paid --> [*]
A <<choice>> state branches on a condition without being a real state itself.

Common mistakes and how to fix them

A state name contains spaces, for example In Review --> Done.
Use an ID without spaces, or declare it with state "In Review" as InReview.
A note is not closed.
Multi-line notes must end with end note.
Using stateDiagram and expecting newer features.
Prefer stateDiagram-v2, the current renderer.

Export your state diagram

Download a PNG, SVG or PDF straight from the playground above. For more options, such as a 1x to 4x scale, a transparent background or copying the image, choose Open in editor and use the Export menu there. Export is free, needs no account and adds no watermark.

Frequently asked questions

What is the difference between stateDiagram and stateDiagram-v2?

Both use the same syntax. stateDiagram-v2 uses the newer renderer, which handles composite states and styling better, so it is the recommended keyword.

How do I show start and end states?

Use [*]. [*] --> Idle draws the start point and Done --> [*] draws the end point.

Can a state diagram show parallel states?

Yes. Inside a composite state, separate concurrent regions with a line containing only --, or use <<fork>> and <<join>> states.

Is a state diagram the same as a flowchart?

No. A flowchart shows steps in a process; a state diagram shows the conditions an object can be in and the events that change them. For process steps, use the flowchart (graph TD) editor on the homepage.