Skip to content

Mermaid Diagrams ​

Mermaid is an open source JavaScript library (MIT License) that draws diagrams from a text description: you write the structure of the diagram with a simple syntax, similar to Markdown, and Mermaid lays it out and draws it as an SVG image. Created by Knut Sveidqvist, it is supported by GitHub, GitLab, Azure DevOps, Notion, Obsidian and many other tools.

A diagram written as text is easy to write, to read in the source and to keep up to date together with the document: no drawing tool, no image to export again after each change, and the version control shows the differences line by line.

Mermaid in Markdown ​

A mermaid diagram is written in a fenced code block with the language mermaid:

markdown
```mermaid
flowchart LR
  A[Markdown] --> B(Markdown Processor)
  B --> C[HTML]
```

The Markdown Processor, with the mexMermaid extension (enabled in the GitHub dialect, the default), writes the block as <pre class="mermaid">, which the Mermaid library turns into the drawing when the page is shown:

WhereThe diagram
Markdown Help Viewerdrawn (with Microsoft Edge WebView2)
Preview of the Markdown Text Editordrawn (with Microsoft Edge WebView2)
TEdgeMarkdownViewer component (Delphi 12 and 13)drawn
Preview Panel of Windows Explorer, TMarkdownViewer component, viewers without WebView2its source text is shown

The Help Viewer, the Editor and the applications that use TEdgeMarkdownViewer draw the diagrams also without an Internet connection: Mermaid 11.17.2 is installed with them, in the Scripts folder (see Deploy an application with TEdgeMarkdownViewer); without that folder it is loaded from the jsDelivr CDN.

The kinds of diagram ​

The first word of the block chooses the kind of diagram. The main ones:

DiagramFirst lineUseful for
Flowchartflowchart LR (or graph TD)processes, algorithms, architectures
Sequence diagramsequenceDiagrammessages between actors and systems
Class diagramclassDiagramclasses, properties, methods and relations (UML)
State diagramstateDiagram-v2states and transitions
Entity RelationshiperDiagramdatabase tables and relations
User Journeyjourneythe steps of a user, with the satisfaction
Ganttganttproject planning
RequirementrequirementDiagramrequirements and their verification (SysML)
Git graphgitGraphbranches, commits and merges
C4C4Contextsoftware architecture (C4 model)
Mindmapmindmapideas organized around a central topic
Timelinetimelineevents in chronological order
Blockblock-betablocks placed by the author
Packetpacket-betathe fields of a network packet
Kanbankanbantasks in columns
Architecturearchitecture-betacloud services and their connections

Mermaid draws also charts (pie, bar and line, quadrant, sankey, radar, treemap): see Charts.

Examples ​

Flowchart ​

markdown
```mermaid
flowchart TD
  Start([Open a file]) --> Kind{Markdown?}
  Kind -- Yes --> Process[Convert to HTML]
  Kind -- No --> Show[Show the HTML]
  Process --> Show
```

flowchart

Sequence diagram ​

markdown
```mermaid
sequenceDiagram
  participant App as Delphi application
  participant Viewer as Markdown Help Viewer
  App->>Viewer: Help request (HelpContext)
  Viewer->>Viewer: Find the Markdown file
  Viewer-->>App: Help shown
```

sequence

Class diagram ​

markdown
```mermaid
classDiagram
  class TMarkdownProcessor {
    +Config: TConfiguration
    +AllowUnsafe: Boolean
    +Process(source) string
  }
  TMarkdownProcessor <|-- TMarkdownCommonMark
  TMarkdownCommonMark <|-- TMarkdownGFM
  TMarkdownProcessor <|-- TMarkdownDaringFireball
```

class

State diagram ​

markdown
```mermaid
stateDiagram-v2
  [*] --> Editing
  Editing --> Saved: Save
  Saved --> Editing: Change
  Saved --> [*]: Close
```

state

Entity Relationship ​

markdown
```mermaid
erDiagram
  CUSTOMER ||--o{ ORDER : places
  ORDER ||--|{ ORDER_LINE : contains
  PRODUCT ||--o{ ORDER_LINE : "ordered in"
```

er

Gantt ​

markdown
```mermaid
gantt
  title Release plan
  dateFormat YYYY-MM-DD
  axisFormat %d %b
  section Development
    New engine      :done, eng, 2026-07-01, 60d
    WebView2 viewer :active, view, after eng, 20d
  section Release
    Documentation   :doc, after view, 7d
```

gantt

Mindmap ​

markdown
```mermaid
mindmap
  root((Markdown Tools))
    Help Viewer
    Text Editor
    Shell Extensions
    Markdown Processor
```

mindmap

Git graph ​

markdown
```mermaid
gitGraph
  commit
  branch feature
  commit
  commit
  checkout main
  commit
  merge feature
```

gitgraph

Learn more ​

The complete syntax of each kind of diagram, the options (themes, directions, styles, links, notes, icons) and many examples are in the official documentation: mermaid.js.org. To try a diagram before writing it in a document, use the online editor mermaid.live.

Some diagrams marked as -beta can change in the next versions of Mermaid: the documentation of the version used by the tools (11.17.2) is the reference.

Released under Apache License, Version 2.0.