technologies · difficulty ◆◆
Mermaid — diagrams as code
Stop drawing diagrams. Start writing them.
A Swedish architect lost a Microsoft Visio file in 2014 and decided the fix was not a better diagram editor — it was to stop drawing diagrams entirely and write them as text instead. That decision became Mermaid, and it quietly became the default way the modern web draws.
AI-generated draft · reviewed and editedThis text was generated with AI as a first draft, then reviewed and edited by the author, who holds editorial responsibility for it.$ mermaid- 90.7k
- GitHub stars
- 11.17.2
- current version
- 2014
- created
- MIT
- license
- 15+
- diagram types
mermaid-js/mermaid, verified 2026-10-15
mermaid package, installed here
Knut Sveidqvist, after losing a Visio file
open source
flowchart, sequence, gantt, class, er, pie, mindmap…
What it is
Mermaid is a JavaScript library that turns markdown-like text into diagrams. You write a few lines describing nodes and edges, and it renders a flowchart, sequence diagram, Gantt chart, class diagram, entity-relationship diagram, pie chart, mind map, or state diagram as an SVG. The source is plain text, so it diffs in git, reviews in pull requests, and renders in GitHub, GitLab, Notion, Obsidian, and a dozen other tools natively.
Why it matters
The failure mode Mermaid kills is doc-rot. A diagram you draw in Visio or draw.io is a binary blob: it cannot be diffed, it drifts from the code it describes, and it dies with the person who owns the file. A Mermaid diagram is text, so it lives in the same repository as the code, gets reviewed in the same pull request, and updates in the same commit. When the architecture changes, the diagram changes with it — or the review catches it. That is the whole bet: diagrams as code, not as artifacts.
How it fits your stack
Mermaid is installed in this environment at version 11.17.2 — it is a runtime dependency of this site, which bundles the renderer and also keeps pre-generated SVG for the diagrams it shows inline. It renders in the browser from a single script tag, or server-side to SVG for static sites. The diagrams embedded on this page are Mermaid output saved as static SVG files, so they load fast and match the site theme. You can also run it in CI to fail a build when a diagram is malformed, or use the live editor at mermaid.live to sketch before you commit.
Example
$ flowchart LR
A[Write text] --> B[Parse] --> C[Render SVG] A[Write text] --> B[Parse] --> C[Render SVG]
# renders a left-to-right flowchart with three nodes
# and two arrows — that is the whole syntaxThe minimal flowchart. `LR` = left-to-right; `TD` = top-down. `[text]` is a rectangle node, `-->` is an arrow.
$ flowchart TD
A[Start] --> B{Is it a diagram?}
B -- yes --> C[Write mermaid text]
B -- no --> D[Write prose]
C --> E[Render] --> F[Commit to git] --> G[Ship docs] A[Start] --> B{Is it a diagram?}
B -- yes --> C[Write mermaid text]
B -- no --> D[Write prose]
C --> E[Render] --> F[Commit to git] --> G[Ship docs]
# {} is a decision diamond, -- label --> is a labeled edgeA real decision flow. `{}` makes a diamond, and `-- yes -->` labels the edge. This is the shape of most flowcharts you will ever write.
$ sequenceDiagram
participant U as User
participant B as Browser
participant M as Mermaid
U->>B: open docs page
B->>M: render("flowchart", src)
M-->>B: SVG string
B-->>U: draw diagram User -> Browser -> Mermaid
open docs page
render("flowchart", src)
SVG string
draw diagram
# sequence diagrams model message passing between actorsSequence diagrams model who talks to whom, in order. `->>` is a solid arrow, `-->>` a dashed reply. `participant X as Label` renames the actor.
$ gantt
title Project Timeline
dateFormat YYYY-MM-DD
section Build
Frontend :b1, 2026-09-10, 10d
Backend :b2, 2026-09-10, 12d
section Ship
QA :c1, 2026-09-22, 5d
Launch :c2, after c1, 2d gantt
title Project Timeline
dateFormat YYYY-MM-DD
section Build
Frontend :b1, 2026-09-10, 10d
Backend :b2, 2026-09-10, 12d
section Ship
QA :c1, 2026-09-22, 5d
Launch :c2, after c1, 2d
# a Gantt chart from a few lines of textGantt charts track tasks over time. `section` groups tasks, `:id, start, duration` defines each bar, and `after c1` chains dependencies.
$ erDiagram
USER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
USER {
int id PK
string name
string email
} USER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
USER {
int id PK
string name
string email
}
# entity-relationship diagram with cardinalityER diagrams model data. `||--o{` reads as "one to zero or more" and `||--|{` as "one to one or more" — in each marker the outermost character is the maximum and the inner one the minimum. Fields go inside the entity block with `PK`/`FK` markers.
Common flags
- flowchart
- directed graphs with nodes, edges, subgraphs, and decision diamonds
- sequenceDiagram
- message-passing between participants, in time order
- gantt
- task bars over a timeline, with sections and dependencies
- classDiagram
- classes, inheritance, composition, and relationships
- erDiagram
- entities, attributes, and cardinality for data models
- stateDiagram-v2
- state machines with transitions and guards
- pie
- pie chart from label : value pairs
- mindmap
- hierarchical mind map from indented text
- journey
- user-journey diagram with task scores
- gitGraph
- git commit/branch/merge history
- timeline
- chronological events with sections
- quadrantChart
- points plotted in four quadrants
- requirementDiagram
- requirements and their relationships
- C4Context
- C4 architecture context diagrams
- sankey
- flow magnitude between nodes
History
Origin
Mermaid was created in 2014 by Knut Sveidqvist, a Swedish software architect. The origin story is specific: he lost a Microsoft Visio file and realized the real problem was not a better editor but the whole model of diagrams as binary files. If a diagram were text, it could live in version control, diff cleanly, and stay in sync with the code it describes. He named the project after The Little Mermaid, which his children were watching at the time. The first commit landed in November 2014, and the project has been open-source and MIT-licensed ever since.
The diagrams-as-code idea
The core insight borrows from how code already works: text is the most durable, diffable, reviewable format we have. A Mermaid diagram is a few lines of markdown-like syntax that describes structure — nodes, edges, participants, tasks — and the renderer turns that into SVG. Because the source is text, it participates in the same workflows as code: pull requests, code review, git blame, CI. This is the same bet that made Markdown replace WYSIWYG editors for documentation, applied to diagrams.
Growth & adoption
Mermaid grew from a solo project into the default diagram format of the modern web. GitHub renders it natively in Markdown, as do GitLab, Notion, Obsidian, and many more. In 2019 it won the JS Open Source Award for "the most exciting use of technology". In 2022 Sveidqvist co-founded Mermaid Chart Inc. to build hosted editing and enterprise features on top of the open-source library. As of October 2026 the mermaid-js/mermaid repository has over 90,000 GitHub stars, and the library is at version 11.17.2.
Under the hood
The pipeline: text to SVG
Every Mermaid diagram runs the same pipeline. The source text goes through a lexer and parser that build an abstract syntax tree of the diagram — nodes, edges, and their attributes. A layout engine then positions those elements: flowcharts use a layered graph layout, sequence diagrams stack participants and messages, Gantt charts map tasks onto a time axis. Finally the positioned elements are serialized to SVG. Because the layout is computed, you describe structure and Mermaid decides the geometry — which is why the same source renders consistently everywhere.
Why it renders everywhere
Mermaid is a single JavaScript library that runs in any browser, and it can also run server-side to produce static SVG. That is why GitHub, GitLab, Notion, and Obsidian all support it: they each embed the same renderer. For a static site like kmail.at, rendering to SVG ahead of time means each diagram ships as a plain file — fast to load, cacheable, and themeable — and the renderer is bundled for the interactive diagram playground. The diagrams on this page were produced that way, with the site's dark terminal palette baked into the SVG.
Theming and customization
Mermaid supports themes and theme variables, so diagrams can match a brand or a site. The dark theme used on kmail.at sets the background to the site's void color, node fills to the panel color, borders to the green accent, and edges to cyan — the same tokens as the rest of the design. You can also style individual nodes inline with `style A fill:#0F1A16,stroke:#4ADE80`, which is how the diagrams on this page highlight different stages.
Fun facts
Pros & cons
pros
- + Text source diffs in git, reviews in pull requests, and stays in sync with code
- + Renders natively in GitHub, GitLab, Notion, Obsidian, and many more tools
- + 15+ diagram types from one small syntax — no per-type tool to learn
- + MIT-licensed, free, and runs in any browser or server-side to SVG
- + Themeable to match a brand or site design
cons
- − Not a general drawing tool — wrong for free-form illustration or pixel-perfect layout
- − Complex diagrams can get cramped; layout is automatic, not hand-tuned
- − Syntax errors fail silently in some renderers (no error until you look closely)
- − Very large diagrams can be slow to render or hard to read
Takeaways
- 1Start at mermaid.live — type on the left, see the SVG on the right, copy the source into your docs
- 2Learn the four that cover most needs: flowchart, sequenceDiagram, gantt, and erDiagram
- 3Keep diagrams in the same repo as the code so they update in the same commit
- 4Pre-render to SVG at build time for static sites — fast, cacheable, themeable
- 5Use the live editor to sketch, then commit the source so it diffs and reviews like code
