Skip to main content

Mermaid flowchart cheat sheet

Flowcharts connect actions and decisions into a process. Use swimlane subgraphs to group responsibility, or a sequence diagram when the order of messages between systems is the main point.

Build this in Mermaid Flowchart Editor →

Quick start

Keep ids stable and put display labels in quotes. The shape carries meaning; edges connect the ids.

Mermaid
flowchart LR
  D["Draft guide"] --> R{"Approved?"}
  R -->|Yes| P["Publish guide"]
  R -->|No| D

Loading…

Syntax reference

Syntax reference
SyntaxMeaning
flowchart / graph / LR / RL / TB / TD / BTDeclare the diagram and choose direction. TD and TB both mean top to bottom.
A[Text] / A(Text) / A([Text]) / A[[Text]] / A[(Text)]Legacy rectangle, rounded rectangle, stadium, subroutine and cylinder notation.
A((Text)) / A{Text} / A{{Text}} / A>Text] / A(((Text)))Legacy circle, diamond, hexagon, asymmetric shape and double circle.
A[/Text/] / A[\Text\] / A[/Text\] / A[\Text/]Legacy parallelograms and trapezoids in both orientations.
A@{ shape: rect, label: "Text" }Expanded shape notation: select a canonical name or an alias in the shape catalog below.
--> / --- / -.-> / -.- / ==> / === / ~~~Arrow, plain link, dotted arrow/link, thick arrow/link and invisible layout link.
<--> / o--o / x--x / --o / --xBidirectional arrow, circle and cross endpoints.
A -->|Label| B / A -- Label --> B / A ----> BAdd edge text or extra dashes for a longer minimum rank span; exact pixel lengths are not fixed.
subgraph id [Label] / direction TB / endGroup nodes; external links to internal nodes can override the subgraph direction.
classDef / class A,B name / A:::nameDefine and apply reusable visual styles.
style A / linkStyle 0 / e1@--> / class e1 nameStyle a node, a zero-based edge index or a named edge. Named edge styles can also control animation.
click A href "URL" / click A callback "Tooltip"Interactive links and callbacks depend on host security; strict previews disable them.
A["`**Bold** and *italic*`"]Markdown strings support emphasis and automatic wrapping.
A@{ icon: "fa:user", form: "square", pos: "t", h: 60 }Icon nodes require the host to register an icon pack. Square, circle and rounded forms are supported.
A@{ img: "/favicon.svg", label: "Text", w: 60, h: 60, constraint: "on" }Image nodes accept a URL, label, dimensions and aspect-ratio constraint; the image must be reachable.
config.layout: elk / config.flowchart.defaultRenderer: elkELK is an optional layout renderer; it must be installed and registered by the embedding host.
%% / accTitle: / accDescr:Comments and accessible diagram descriptions.
@{ shape: rect } / proc / process / rectangleProcess
@{ shape: rounded } / eventEvent
@{ shape: stadium } / terminal / pillTerminal Point
@{ shape: fr-rect } / subprocess / subproc / framed-rectangle / subroutineSubprocess
@{ shape: cyl } / db / database / cylinderDatabase
@{ shape: datastore } / data-storeData Store
@{ shape: circle } / circStart
@{ shape: bang } / bangBang
@{ shape: cloud } / cloudCloud
@{ shape: diam } / decision / diamond / questionDecision
@{ shape: hex } / hexagon / preparePrepare Conditional
@{ shape: lean-r } / lean-right / in-outData Input/Output
@{ shape: lean-l } / lean-left / out-inData Input/Output
@{ shape: trap-b } / priority / trapezoid-bottom / trapezoidPriority Action
@{ shape: trap-t } / manual / trapezoid-top / inv-trapezoidManual Operation
@{ shape: dbl-circ } / double-circleStop
@{ shape: text }Text Block
@{ shape: notch-rect } / card / notched-rectangleCard
@{ shape: lin-rect } / lined-rectangle / lined-process / lin-proc / shaded-processLined/Shaded Process
@{ shape: sm-circ } / start / small-circleStart
@{ shape: fr-circ } / stop / framed-circleStop
@{ shape: fork } / joinFork/Join
@{ shape: hourglass } / hourglass / collateCollate
@{ shape: brace } / comment / brace-lComment
@{ shape: brace-r }Comment Right
@{ shape: braces }Comment with braces on both sides
@{ shape: bolt } / com-link / lightning-boltCom Link
@{ shape: doc } / doc / documentDocument
@{ shape: delay } / half-rounded-rectangleDelay
@{ shape: h-cyl } / das / horizontal-cylinderDirect Access Storage
@{ shape: lin-cyl } / disk / lined-cylinderDisk Storage
@{ shape: curv-trap } / curved-trapezoid / displayDisplay
@{ shape: div-rect } / div-proc / divided-rectangle / divided-processDivided Process
@{ shape: tri } / extract / triangleExtract
@{ shape: win-pane } / internal-storage / window-paneInternal Storage
@{ shape: f-circ } / junction / filled-circleJunction
@{ shape: notch-pent } / loop-limit / notched-pentagonLoop Limit
@{ shape: flip-tri } / manual-file / flipped-triangleManual File
@{ shape: sl-rect } / manual-input / sloped-rectangleManual Input
@{ shape: docs } / documents / st-doc / stacked-documentMulti-Document
@{ shape: st-rect } / procs / processes / stacked-rectangleMulti-Process
@{ shape: bow-rect } / stored-data / bow-tie-rectangleStored Data
@{ shape: cross-circ } / summary / crossed-circleSummary
@{ shape: tag-doc } / tag-doc / tagged-documentTagged Document
@{ shape: tag-rect } / tagged-rectangle / tag-proc / tagged-processTagged Process
@{ shape: flag } / paper-tapePaper Tape
@{ shape: odd }Odd
@{ shape: lin-doc } / lined-documentLined Document

Expanded shapes and quoted labels

The catalog covers every standard flowchart shape in the installed 11.15 renderer, including aliases. Use @{ shape: ... } for new shapes; older bracket notation remains valid. Quote labels containing punctuation.

Mermaid
flowchart TB
  A@{ shape: sl-rect, label: "Enter title" }
  B@{ shape: doc, label: "Draft document" }
  C@{ shape: diam, label: "Complete?" }
  D@{ shape: cyl, label: "Archive" }
  A --> B --> C
  C -->|Yes| D
  C -->|No| A

Loading…

Grouping with a local direction

Direction inside a subgraph works only where the global layout can respect it. When nodes connect outside their subgraph, Mermaid may inherit the parent direction. Use subgraph-to-subgraph edges when preserving local direction matters.

Mermaid
flowchart LR
  subgraph prep ["Preparation"]
    direction TB
    A["Outline"] --> B["Draft"]
  end
  subgraph review ["Review"]
    direction TB
    C["Check"] --> D["Approve"]
  end
  prep --> review

Loading…

Classes, edge ids and markdown labels

ClassDef makes a reusable style. Apply it with class or :::; direct style targets one node. LinkStyle uses declaration order starting at zero, while a named edge can receive a class. Markdown labels provide emphasis without HTML labels.

Mermaid
flowchart LR
  A["`**Guide** draft`"]:::focus e1@--> B["Review"]
  B --> C["Publish"]
  classDef focus fill:#d3e5ff,stroke:#0070f3,color:#171717
  class B focus
  style C stroke-width:2px
  linkStyle 1 stroke:#0070f3,stroke-width:2px
  classDef edge stroke:#0070f3
  class e1 edge

Loading…

Spacing and renderer selection

Node and rank spacing tune the default layout. Large graphs may benefit from ELK, but a host must supply the optional renderer. Icon packs also need host registration; ordinary shapes work without either extension.

Mermaid
---
config:
  flowchart:
    nodeSpacing: 35
    rankSpacing: 60
---
flowchart LR
  A["Write"] --> B["Review"] --> C["Publish"]

Loading…

Common mistakes

Leaving a shape open

Close the node brackets and quote the label.

Invalid syntax — corrected example below

flowchart LR
  A[Draft

Using bare end as a node id

End closes a subgraph. Use a different stable id, then put the display word inside a quoted label.

Expecting click actions in strict mode

The host controls security. This site deliberately disables diagram callbacks; the separate editor links remain usable.

Limitations

  • Automatic layout determines exact positions; longer links request rank spans rather than fixed pixel lengths.
  • External edges can override a subgraph’s direction.
  • Icons require a registered pack, images require reachable assets, and ELK requires host registration.

Frequently Asked Questions

How do I choose a new Mermaid shape?
Use A@{ shape: name, label: "Text" } with a shape name or alias from the catalog. Legacy bracket notation still works.
Why is my subgraph direction ignored?
Edges from internal nodes to outside nodes can cause the subgraph to follow its parent’s direction. Link the subgraphs themselves when practical.
How do I style just one edge?
Use linkStyle with its zero-based declaration index, or assign an edge id and apply a visual class to that id.