Diagrams / Mermaid State Diagram: Syntax & Examples

Mermaid State Diagram: Syntax & Examples

Explore Mermaid state syntax with lifecycle events and transitions. Read an editable example, inspect boundaries and check missing failure paths.

When to use State Diagram

A Mermaid state diagram documents an object’s lifecycle and the events that change its state. Use it for job processing, order status, or interaction rules. Name stable conditions as states and use transition labels to explain what makes the next condition possible.

Read the State Diagram example

Diagram source

stateDiagram-v2
    [*] --> Draft
    Draft --> Preview: render
    Preview --> Editing: update code
    Preview --> Exported: download PNG
    Editing --> Preview: render again
    Exported --> [*]
The document can move from draft to preview, return to editing, and eventually be exported. The returning transition is a lifecycle rule; it is not the same as a list of UI implementation steps.

How to use this tool

  1. Start with the example in the editor and identify the elements that answer your question.
  2. Replace the sample labels and values, previewing after each structural change.
  3. Review the diagram at its intended reading size, then keep the source and export the format your document accepts.

Syntax and interpretation

ConceptHow to apply it
Boundary markers[*] marks an initial or final boundary depending on where it appears.
EventsWrite a meaningful transition event. Add guard or action text when the rule needs it.
CompletenessCheck failure and cancellation cases as well as the successful path. A state with no intended exit may indicate a missing rule.

Common questions

Does the diagram execute my state machine?

No. It is documentation. Validate the actual transition logic and allowed events in your implementation separately.