Draw a top-down flowchart
TD and TB both lay out the flowchart from top to bottom.
Open this example in playgroundFind diagram syntax, copy a complete example, and open it in the playground to make it your own.
Choose a direction and connect your first two nodes.
TD and TB both lay out the flowchart from top to bottom.
Open this example in playgroundLR lays out the flowchart from left to right.
Use RL for right-to-left or BT for bottom-to-top. Both graph and flowchart are valid declarations.
Open this example in playgroundKeep a stable node ID and change the surrounding label syntax.
Parentheses give a node rounded corners. Square brackets create a plain rectangle.
Open this example in playgroundDouble parentheses draw a circle around the label.
Open this example in playgroundSquare brackets with inner parentheses create a cylinder.
Open this example in playgroundBraces create a diamond. Label the outgoing arrows to explain each branch.
Open this example in playgroundTriple parentheses create a double circle.
Open this example in playgroundShow direction, plain connections, and labelled relationships.
--> draws a directed edge with an arrowhead.
Open this example in playground--- draws a line without an arrowhead.
Open this example in playgroundUse pipes for edge labels, -.-> for a dotted arrow, and ==> for a thick arrow.
Open this example in playgroundGroup related nodes and reuse visual styles.
A subgraph has its own ID and an optional readable label; end closes the group.
You can set direction inside a subgraph, but links to outside nodes can make it inherit the parent direction.
Open this example in playgroundstyle targets a node ID and accepts comma-separated CSS properties.
Set text color alongside fill so labels stay readable in both light and dark themes.
Open this example in playgroundDefine a class with classDef, then assign it to one or more node IDs.
Open this example in playgroundThe ::: suffix assigns a declared class directly to a node.
Open this example in playgroundDeclare participants, send requests, and show replies or active work.
Aliases separate a short ID from its displayed label. actor draws a person instead of a participant box.
Open this example in playground-> and --> have no arrowhead; ->> and -->> have an arrowhead.
Reverse direction by swapping the sender and receiver. Do not use flowchart forms such as <-- or <--> here.
Open this example in playgroundActivation bars show when a participant is doing work. Balance each activate with a deactivate.
Open this example in playground+ activates the receiver; - deactivates the sender.
Open this example in playgroundUse Note left of, Note right of, or Note over one or two participants.
Note above is not sequence-diagram syntax.
Open this example in playgroundShow alternatives, repeated requests, and parallel work.
alt and else describe branches; end closes the block. Use opt for a single optional branch.
Open this example in playgroundloop labels a repeated sequence. autonumber numbers messages automatically.
Open this example in playgroundpar starts parallel branches, and introduces another branch, and end closes the block.
Open this example in playgroundDescribe fields, methods, and relationships between types.
Members without parentheses are attributes; members with parentheses are methods.
+ is public, - private, # protected, and ~ package/internal visibility.
Open this example in playgroundThe triangle points to the parent type. Diamonds sit at the owning end of a relationship.
Open this example in playgroundModel database relationships or transitions through a lifecycle.
|| means exactly one; o{ means zero or more. Here each order has one user and a user can have many orders.
Use PK, FK, and UK to label primary, foreign, and unique keys. Mermaid describes the schema; it does not enforce constraints.
Open this example in playground[*] marks the initial or final state. Add transition labels after a colon.
Open this example in playgroundShow proportions, project dates, or a Git branch history.
Provide a quoted label and numeric value for each slice.
These are illustrative values, not measured statistics. Values need not sum to 100.
Open this example in playgroundGive tasks IDs to express dependencies with after. done and active label task status.
Dates are fixed example data; active is an explicit status, not a claim about today's progress.
Open this example in playgroundbranch creates and checks out a branch. checkout switches branches; merge creates a merge commit.
This draws an illustrative history; it does not execute Git commands.
Open this example in playgroundConfigure a complete diagram or link a node to documentation.
YAML frontmatter goes before the diagram declaration. Built-in themes include default, dark, forest, neutral, and base.
Older examples may use %%{init: ...}%% directives. For custom themeVariables, use theme: base; host support and configuration can vary.
Open this example in playgroundclick attaches a URL to a node ID.
Links depend on the host's security policy. This playground allows links; an inline securityLevel directive cannot override a host's secured setting.
Open this example in playgroundAvoid parser surprises with labels, reserved words, and comments.
Use simple IDs for connections and quoted labels for punctuation or readable text.
Open this example in playground%% begins a comment. Quote a literal lowercase end label so it is not confused with a block terminator.
Open this example in playground