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 --> [*]How to use this tool
- Start with the example in the editor and identify the elements that answer your question.
- Replace the sample labels and values, previewing after each structural change.
- Review the diagram at its intended reading size, then keep the source and export the format your document accepts.
Syntax and interpretation
| Concept | How to apply it |
|---|---|
| Boundary markers | [*] marks an initial or final boundary depending on where it appears. |
| Events | Write a meaningful transition event. Add guard or action text when the rule needs it. |
| Completeness | Check 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.