Atlas
  • All-in-one
  • Solutions
  • Compare
  • Pricing
PricingGet started
All guides
July 11, 2026·9 min read·mermaid, state diagram, state machine, tutorial

Mermaid State Diagram Tutorial (State Machines)

A state diagram shows the states something can be in and how it moves between them. Mermaid makes state machines quick to write and revise.

A state diagram models something that can be in one of several states and moves between them in response to events. An order is pending, then paid, then shipped, then delivered; a user account is active, suspended, or closed; a network connection is connecting, connected, or disconnected. State diagrams capture exactly these possibilities and transitions, making them invaluable for modeling anything with a lifecycle. Mermaid's state diagram syntax is clean and lets you write a state machine in text that stays close to the code implementing it.

This tutorial covers defining states, drawing transitions between them, marking the start and end, and the more advanced constructs - composite states that nest, and choice points that branch on a condition. Each concept comes with a snippet you can render in the live editor at /diagram-tools/mermaid-editor. Use the `stateDiagram-v2` keyword, which is the current, improved version of Mermaid's state diagram syntax and the one you should always start with.

States and transitions

A state diagram begins with `stateDiagram-v2`. States are named, and transitions between them are drawn with an arrow: `Still --> Moving` creates two states and a transition from Still to Moving. You label a transition - the event that triggers it - with a colon: `Still --> Moving : go` shows that the "go" event moves the system from Still to Moving. Transition labels are important because they explain why a state change happens, not just that it can.

Every state machine needs a starting point, and Mermaid represents it with the special `[*]` marker. Writing `[*] --> Still` means the machine begins in the Still state. The same `[*]` marker used as a target represents an end state: `Moving --> [*]` means from Moving the machine can terminate. These initial and final pseudo-states render as the standard filled-circle and bullseye markers from UML state diagrams, so the entry and exit points are unmistakable.

Naming states with descriptions

State names are often short identifiers, but you frequently want a longer, more readable label in the diagram. Mermaid lets you separate the identifier from the display text with the `as` keyword: `state "Waiting for payment" as pending` defines a state whose ID is `pending` but which displays "Waiting for payment". You then use the short `pending` ID in transitions, keeping the transition lines concise while the diagram shows friendly labels.

This separation matters more than it first appears. Short IDs make the transition definitions readable and easy to type, while descriptive labels make the rendered diagram clear to someone who did not write it. For a state machine with a dozen states, using clear IDs and descriptive labels is the difference between a diagram that documents the system well and one that only its author can decode.

Composite states and choices

Real systems often have states that contain sub-states. Mermaid supports these composite states by nesting: you write `state Active {` and inside the braces define sub-states and their transitions, closing with `}`. This lets you model, say, an "Active" state that internally has "Idle" and "Processing" sub-states, collapsing detail when you want the big picture and expanding it when you need the internals. Composite states are the main tool for managing complexity in larger state machines.

  • `[*]` marks both the initial state (as a source) and a final state (as a target).
  • `State1 --> State2 : event` draws a labelled transition triggered by an event.
  • `state "Long label" as short` separates a readable label from a concise ID.
  • `state Name { ... }` nests sub-states inside a composite state.
  • A choice pseudo-state, `state fork <<choice>>`, branches to different states based on a condition.
  • Fork and join (`<<fork>>` and `<<join>>`) model concurrent sub-states splitting and rejoining.
  • `note right of State : text` attaches an explanatory note to a state.

Choices, notes, and next steps

Sometimes a transition depends on a condition, and Mermaid models this with a choice pseudo-state. You declare one with `state if_state <<choice>>`, then draw transitions into it and out of it with guard conditions as labels - the incoming transition reaches the choice, and the outgoing transitions branch to different states depending on the condition, which you write as the transition label. This keeps conditional branching explicit in the state machine rather than hiding it.

Notes work as in other Mermaid diagrams: `note right of Active : Handles all live requests` attaches explanatory text to a state, letting you document the meaning or behavior of a state beyond its name. Together, these features let Mermaid express genuinely sophisticated state machines in readable text. When you want to lay one out precisely for documentation or a presentation, you can import the Mermaid into Atlas Diagram Studio and refine it visually on the canvas at /diagrams, keeping the text source editable in the Mermaid editor at /diagram-tools/mermaid-editor.

Keep reading

  • Best Diagramming Software in 2026: The Overall Buyer Guide
  • How to Make Diagrams for Confluence
  • How to Make Diagrams for Notion
  • Free PDF tools
  • The all-in-one work OS

FAQ

Questions, answered.

How do I mark the start of a state machine in Mermaid?
Use the special [*] marker as the source of a transition: [*] --> Idle means the machine begins in the Idle state. The same [*] marker used as a target represents an end state, like Done --> [*]. These render as the standard filled-circle start and bullseye end markers from UML state diagrams.
How do I label what triggers a transition?
Add the event after a colon on the transition line: Still --> Moving : go shows that the "go" event causes the move from Still to Moving. Transition labels are important because they explain why a state change happens. Without them, a diagram shows that transitions are possible but not what triggers them.
What is a composite state in Mermaid?
A composite state contains sub-states. You define one by nesting: state Active { ... } with sub-states and transitions inside the braces. Composite states let you collapse detail for the big picture and expand it for the internals, which is the main way to manage complexity in a larger state machine.
How do I show a conditional branch in a state diagram?
Use a choice pseudo-state: declare state check <<choice>>, draw a transition into it, then draw outgoing transitions to different states with guard conditions as their labels. This keeps conditional branching explicit in the state machine, showing that the next state depends on a condition evaluated at the choice point.
Should I use stateDiagram or stateDiagram-v2?
Always use stateDiagram-v2. It is the current, improved version of Mermaid's state diagram syntax with better layout and more features. The original stateDiagram keyword still works for compatibility, but new diagrams should start with stateDiagram-v2 to get the best rendering and full feature support.

Ready when you are

One workspace, not ten.

Atlas replaces the stack with one platform for tasks, projects, CRM, contracts, e-signature, PDF tools, and analytics. Start free.

Get started freeSee pricing
AtlasWork, planned itself.

The AI-native, all-in-one work platform. Tasks, projects, CRM, contracts, and analytics in one calm workspace.

All systems operational
  • SOC 2 II
  • ISO 27001
  • HIPAA
  • GDPR

Product

  • Overview
  • PDF tools
  • People & HR
  • Integrations
  • Marketplace
  • Pricing

Resources

  • Guides
  • Docs
  • API reference
  • Support
  • Changelog
  • Status

Company

  • About
  • Careers
  • Press
  • Contact

Legal & trust

  • Trust center
  • Security
  • Privacy
  • Terms
  • DPA
  • GDPR
  • SLA
  • Refunds
Atlas, a product by wrxstack.com·© 2026 wrxstack·All rights reserved
PrivacyTermsSecurityStatus