Unsaved
Ready
Loading Monaco Editor...
Preview
Styling
Flowchart
All diagram types

Mermaid Flowchart Syntax & Examples — Live Editor

Flowcharts turn a process into nodes and arrows: steps, decisions, and the path between them. Edit the diagram above, or copy one of the examples below.

Examples

Copy an example, or open it in the live editor with this diagram already loaded.

Checkout decision path

A top-down checkout flow with a sign-in check and a payment branch. Diamond nodes are decisions; labels on the arrows are the answers.

flowchart TD
    A([Open cart]) --> B{Signed in?}
    B -->|No| C[Sign in]
    C --> B
    B -->|Yes| D{Payment accepted?}
    D -->|No| E[Show the error]
    E --> D
    D -->|Yes| F[Create the order]
    F --> G([Confirmation])

Service boundaries with subgraphs

A left-to-right view of a browser, an API, and a database. Subgraphs group nodes that belong to the same system.

flowchart LR
    subgraph Client
        UI[Next.js UI]
    end
    subgraph Server
        API[Route handler]
        DB[(Postgres)]
    end
    UI -->|HTTPS| API --> DB

CI pipeline

A build pipeline that branches on the target branch. The stadium shape marks the start, and the decision node picks deploy or preview.

flowchart TB
    Start([Git push]) --> Lint[Lint and typecheck]
    Lint --> Test[Run tests]
    Test --> Build[Production build]
    Build --> Target{Branch is main?}
    Target -->|Yes| Deploy[Deploy]
    Target -->|No| Preview[Publish a preview]

What is a Flowchart?

A Mermaid flowchart is a directed graph. Each node is a step or a decision, and each arrow is the path to the next step. Start the diagram with a direction — TD for top-down, LR for left-to-right — then declare nodes by writing an id and a shape. Rectangles hold actions, diamonds hold yes/no questions, and rounded nodes mark the start or end. Use a flowchart when the reader needs to follow one process from a trigger to an outcome, including the branches that depend on a condition.

When to use it

Use a flowchart for approval paths, onboarding, incident response, and algorithm logic. Switch to a sequence diagram when the story is messages between services over time, and to a state diagram when the important fact is which mode an object is in rather than the next step.

Edit this flowchart in the live editor, read the flowchart syntax guide, or compare it with Sequence Diagram, State Diagram and ER Diagram.

Common Use Cases

  • •Process documentation - Map business workflows and procedures
  • •Decision trees - Visualize if/then logic and branching paths
  • •System architecture - Show data flow between components
  • •Algorithm design - Plan code logic before implementation
  • •User journeys - Document how users navigate through an app

Syntax Quick Reference

ElementSyntaxDescription
Rectangle[Text]Process step or action
Rounded(Text)Start or end point
Diamond{Text}Decision point
Circle((Text))Connector or reference
Arrow-->Flow direction
Arrow with label-->|Label|Labeled connection

Syntax tips

  • •Declare the direction on the first line: flowchart TD, LR, BT, or RL. TD is the usual choice for a process; LR fits architecture sketches.
  • •Node ids should be single words. Put the visible label in brackets: login[Sign in]. Spaces in the id are a syntax error.
  • •Put arrow text between pipes: A -->|Yes| B. The label sits on the link, not inside the next node.
  • •Wrap a group in subgraph Name ... end. A subgraph can link to a node outside the group.
  • •style A fill:#1f6feb,color:#fff colors one node. classDef and class reuse the same colors on several nodes.

Common mistakes

Writing graph TD or forgetting the direction keyword.

Start with flowchart TD or flowchart LR. The older graph keyword still renders, but flowchart enables more link styles.

Using end, subgraph, or graph as a node id.

Those words are reserved. Name the node something else and set the label explicitly: finish[End].

Drawing a decision as a rectangle and hiding the branch in the node text.

Use a diamond, {Paid?}, and put Yes and No on the outgoing arrows.

Export Options

Flowcharts are usually read in docs and slide decks. SVG stays sharp when the page is zoomed; PNG is the safer drop-in for Google Slides and Keynote. Free PNG files include a watermark.

Got Mermaid code from ChatGPT? Paste it here to render and export instantly.

Get the Free Mermaid Syntax Cheat Sheet

Free Mermaid Syntax Cheat Sheet

All 21 diagram types in one PDF reference.

Frequently Asked Questions

Ready to create your own flowchart?

Open the editor with this example pre-loaded and start customizing.

Flowchart templates

Related Diagram Types

All diagram types