MDash
By Mohammad AniniLast Updated

Mermaid Diagrams

Explain a process, plan a timeline, or show how parts of a system connect with Mermaid diagrams. Build one through Insert Diagram, or write its source directly in a fenced code block with the mermaid language tag. MDash renders the diagram beside the rest of your Markdown.

Table of Contents

Diagram Structure

The first line inside the fence selects the diagram type. The remaining lines define nodes, relationships, labels, or data:

Mermaid Source

```mermaid
flowchart LR
  accTitle: Markdown to Preview
  accDescr: Markdown source is rendered into a live preview.
  source["Markdown Source"] --> preview["Live Preview"]
```

Rendered Result

flowchart LR
  accTitle: Markdown to Preview
  accDescr: Markdown source is rendered into a live preview.
  source["Markdown Source"] --> preview["Live Preview"]

Choose View Source → Copy Source on a rendered diagram to try it in your own document. On a touch screen, open Diagram Actions (⋯) in the diagram’s top corner, then choose Source → Copy Source.

Use short identifiers such as source and put readable text inside brackets or quotes. Quote labels that contain spaces, punctuation, or parentheses.

Indentation improves readability, even for diagram types where it is not strictly required. Keep one relationship or declaration per line so syntax errors are easier to locate.

Insert or Edit a Diagram

Choose Insert Diagram in the editing toolbar, or press Ctrl/⌘ + Alt + Shift + D while the editor is focused, then:

  1. Choose a template, such as Flowchart, Sequence, or Gantt.
  2. Edit the Mermaid source.
  3. Check the live preview and correct any reported syntax error.
  4. Choose Insert Diagram when the preview is ready.

To update an existing diagram, place the editor cursor anywhere inside its Mermaid fence and choose Insert Diagram. The dialog opens as Edit Diagram, loads the complete block, and replaces it when you choose Update Diagram.

You can also open Insert Diagram from the command palette. See Available Diagram Types for more formats. Choose View Mermaid Guide in the dialog to open this reference in a separate documentation tab.

In Preview, shared documents, and public guides, use View Source inside a rendered diagram to inspect its definition, then choose Copy Source to copy it. The diagram box keeps its height. Scroll inside the box to read long source. In the diagram view, use the zoom controls or download an image with Download SVG or Download PNG. On touch screens, open Diagram Actions in the top corner and use Source or Diagram to switch views.

Available Diagram Types

Choose the diagram type that answers the reader's question:

QuestionDiagram TypeExample
What happens next?FlowchartDraft, review, revise, and publish a document
Who sends what, and when?SequenceA traveler asks a booking service for flights
What states can an item have?StateAn issue moves from open to resolved
How is information related?Entity Relationship or ClassOrders, products, and order items
When will work happen?Gantt or TimelineOverlapping tasks or milestones for a documentation release
How is work progressing?KanbanTasks in Backlog, In Progress, Review, and Done
How do ideas connect?MindmapA language-learning plan
How does an experience feel?User JourneyA visitor's route through a museum
How do quantities compare?PieThe parts of a household budget
How did branches change?Git GraphDrafting and review on separate branches

The bundled Mermaid release also supports specialized formats such as quadrant and XY charts, requirement and architecture diagrams, Sankey diagrams, block and packet diagrams, C4 diagrams, radar charts, treemaps, Venn diagrams, Ishikawa diagrams, event modeling, tree views, and Wardley maps. Formats marked -beta by Mermaid can change between releases. Check the inline preview when using a newer diagram type.

Flowchart

```mermaid
graph TD
  A[Draft] --> B{Ready?}
  B -->|Yes| C[Publish]
  B -->|No| D[Revise]
  D --> A
```
graph TD
  A[Draft] --> B{Ready?}
  B -->|Yes| C[Publish]
  B -->|No| D[Revise]
  D --> A

Use TD for top-to-bottom layouts and LR for left-to-right layouts.

Shapes, Labels, and Subgraphs

flowchart LR
  start([Start]) --> choice{Ready?}
  choice -->|Yes| publish[Publish]
  choice -->|No| revise[Revise]

  subgraph Review
    revise --> choice
  end

Common flowchart forms include [Rectangle], (Rounded), {Decision}, and ([Terminal]). Edge labels use -->|Label|.

Sequence Diagram

Follow messages from top to bottom to see their order. This example separates the traveler, booking service, and airline so readers can tell who is responsible for each step:

sequenceDiagram
  participant T as Traveler
  participant B as Booking Service
  participant A as Airline
  T->>B: Search for a flight
  B->>A: Request availability
  A-->>B: Return available seats
  B-->>T: Show matching flights

Class Diagram

Show types and their relationships. Here, books and magazines share the general properties of a library item:

classDiagram
  class LibraryItem {
    +String title
    +Boolean available
  }
  class Book {
    +String author
    +String isbn
  }
  class Magazine {
    +Number issue
  }
  LibraryItem <|-- Book
  LibraryItem <|-- Magazine

State Diagram

Use states to explain what an item can be and which events move it between states:

stateDiagram-v2
  [*] --> Open
  Open --> Investigating : Assign
  Investigating --> Waiting : Request Information
  Waiting --> Investigating : Reply Received
  Investigating --> Resolved : Fix Confirmed
  Resolved --> [*]

ER Diagram

Use an entity relationship diagram for data relationships and cardinality. This example shows that an order contains order items and each item refers to a product:

erDiagram
  CUSTOMER ||--o{ ORDER : places
  ORDER ||--|{ ORDER_ITEM : contains
  PRODUCT ||--o{ ORDER_ITEM : appears_in
  PRODUCT {
    string id
    string name
    decimal price
  }

Pie Chart

Use a pie chart when the values form a meaningful whole. These budget amounts total 100, making the proportions easy to explain:

pie title Monthly Household Budget
  "Housing" : 40
  "Food" : 25
  "Transport" : 15
  "Savings" : 20

Gantt Chart

A Gantt chart shows tasks against dates. Here, example review starts while the guide is still being drafted.

gantt
  title Documentation Release Plan
  dateFormat YYYY-MM-DD
  section Writing
  Draft the Setup Guide  :2026-11-02, 4d
  Review Examples       :2026-11-04, 4d
  section Release
  Final Review          :2026-11-09, 2d

Mindmap

Group ideas into branches when exploring a topic before committing to a sequence:

mindmap
  root((Learn Spanish))
    Vocabulary
      Travel
      Food
    Practice
      Conversation
      Listening
    Review
      Flashcards
      Weekly Quiz

User Journey

Compare stages of an experience with participant names and scores. These illustrative ratings range from 1 for a poor experience to 5 for a good one. Buying a ticket has the lowest rating, so it would be the first step to review.

journey
  title Visiting a Museum
  section Arrival
    Find the Entrance: 4: Visitor
    Buy a Ticket: 3: Visitor, Staff
  section Explore
    Follow the Map: 4: Visitor
    Join a Guided Tour: 5: Visitor, Guide
  section Finish
    Visit the Museum Shop: 4: Visitor

Git Graph

Explain commits, branches, and merges without a screenshot of a repository. This is a diagram of a workflow; it does not read or modify a Git repository:

gitGraph
  commit id: "Initial Draft"
  branch review
  checkout review
  commit id: "Technical Review"
  commit id: "Apply Feedback"
  checkout main
  merge review id: "Approve"
  commit id: "Publish" tag: "v1.0"

Timeline

Use a timeline to show milestones in order. This example shows the same documentation release without the task durations.

timeline
  title Documentation Release Milestones
  2026-11-02 : Drafting Begins
  2026-11-08 : Examples Verified
  2026-11-11 : Guide Published

Kanban Board

Group tasks by their current status. The board is rendered from source; update the Mermaid text to move a task between columns:

kanban
  backlog[Backlog]
    paint[Choose Paint Colors]
    lighting[Plan Lighting]
  active[In Progress]
    cabinets[Install Cabinets]@{ assigned: 'Carpenter', priority: 'High' }
  review[Review]
    inspection[Electrical Inspection]@{ assigned: 'Inspector' }
  done[Done]
    flooring[Replace Flooring]

Tips

  • Start with a template when you are learning a diagram type.
  • Check the inline preview before inserting a complex diagram.
  • Diagrams adapt to Light and Dark themes.
  • Left-to-right layouts often work better for wide diagrams.
  • Break a complex diagram into smaller diagrams when labels become difficult to read.

For slide-specific layout advice, see Presentation Mode. For color and direction behavior, see Themes and Direction.

Accessibility and Exports

Introduce a diagram with a short sentence that explains its purpose. Important conclusions should also appear in nearby prose because a dense visual can be difficult for screen readers or readers with low vision.

Keep labels concise and use a clear direction. Do not rely on color alone to distinguish states or relationships.

Give a diagram an accessible title and description in its Mermaid source:

Mermaid Source

```mermaid
flowchart LR
  accTitle: Documentation review workflow
  accDescr: A draft moves to review, then either returns for revision or proceeds to publication.
  draft[Draft] --> review{Approved?}
  review -->|No| draft
  review -->|Yes| publish[Publish]
```

Rendered Result

flowchart LR
  accTitle: Documentation review workflow
  accDescr: A draft moves to review, then either returns for revision or proceeds to publication.
  draft[Draft] --> review{Approved?}
  review -->|No| draft
  review -->|Yes| publish[Publish]

MDash centers rendered diagrams in HTML and PDF exports. In document Preview and public guides, diagrams can render as you scroll to them. Review complex diagrams in the target format because page width, fonts, and theme colors can change line wrapping.

Errors and Limitations

An invalid diagram displays an inline Mermaid error instead of breaking the rest of the document. Check the first reported line, diagram type, indentation, and punctuation.

MDash uses Mermaid's strict security mode. Diagram source is treated as document content, and unsafe interactive markup is not trusted.

Complex diagrams can still take time to lay out. Prefer several focused diagrams over one very large graph.