ConfigsApr 12, 2026·2 min read

Mermaid — Generate Diagrams from Text Like Markdown

Mermaid is a JavaScript-based diagramming tool that renders Markdown-inspired text definitions to create diagrams and visualizations. Flowcharts, sequence diagrams, Gantt charts, class diagrams, ER diagrams, and more — all from plain text. Natively supported in GitHub Markdown.

TL;DR
Mermaid generates flowcharts, sequence diagrams, and more from text definitions in Markdown.
§01

What it is

Mermaid is a JavaScript-based diagramming tool that renders Markdown-inspired text definitions into diagrams and visualizations. It supports flowcharts, sequence diagrams, Gantt charts, class diagrams, ER diagrams, state diagrams, and more, all from plain text.

Mermaid is natively supported in GitHub Markdown, GitLab, Notion, Obsidian, and Docusaurus. It lets developers create documentation diagrams without Figma, draw.io, or any visual editor. Written in TypeScript with an MIT license.

§02

How it saves time or tokens

Mermaid eliminates the context switch between writing documentation and creating diagrams. Instead of opening a separate tool, exporting images, and embedding them, you write diagram definitions inline with your documentation. Changes to diagrams are version-controlled alongside code. AI agents can generate and modify Mermaid diagrams as text, which is far more efficient than manipulating image files. The CLI tool renders diagrams to SVG or PNG for contexts that do not support live rendering.

§03

How to use

  1. Write Mermaid diagrams directly in GitHub Markdown:

flowchart TD

A[User visits site] --> B{Logged in?}

B -->|Yes| C[Dashboard]

B -->|No| D[Login page]

D --> E[Enter credentials]

E --> B

  1. Use the CLI for rendering to files:
npm i -g @mermaid-js/mermaid-cli
mmdc -i input.mmd -o output.svg -t dark
mmdc -i input.mmd -o output.png -w 1200
  1. Embed in HTML for web applications:
<script type="module">
  import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
  mermaid.initialize({ startOnLoad: true, theme: 'dark' });
</script>
<pre class="mermaid">
sequenceDiagram
    Client->>API: POST /login
    API->>DB: SELECT user
    DB-->>API: user record
    API-->>Client: JWT token
</pre>
§04

Example

An entity-relationship diagram for a project management system:

erDiagram
    USER ||--o{ PROJECT : owns
    PROJECT ||--|{ TASK : contains
    TASK }o--|| USER : assigned_to
    PROJECT ||--o{ MEMBER : has
    USER ||--o{ MEMBER : participates
§05

Related on TokRepo

§06

Common pitfalls

  • Complex diagrams with many nodes and edges become unreadable. Break large diagrams into multiple smaller ones focused on specific subsystems.
  • Not all Mermaid diagram types are supported in every platform. GitHub supports flowcharts, sequence, class, state, ER, Gantt, pie, and git graphs, but some newer types may lag.
  • Using Mermaid's live editor for collaboration does not save state. Export diagram definitions to your repository for version control.

Frequently Asked Questions

What diagram types does Mermaid support?+

Mermaid supports flowcharts (TD, LR, RL, BT), sequence diagrams, class diagrams, state diagrams, entity-relationship diagrams, Gantt charts, pie charts, git graphs, user journey maps, mindmaps, and timeline diagrams.

Does Mermaid work in GitHub README files?+

Yes. GitHub natively renders Mermaid code blocks in Markdown files including READMEs, issues, pull request descriptions, and wiki pages. Wrap your diagram in a mermaid-tagged code fence.

Can AI agents generate Mermaid diagrams?+

Yes. Since Mermaid diagrams are plain text, AI agents can generate, modify, and version them like any other code. This is more efficient than generating or editing image files.

How do I render Mermaid diagrams to PNG or SVG?+

Use the Mermaid CLI tool: npm i -g @mermaid-js/mermaid-cli, then mmdc -i input.mmd -o output.svg. The CLI supports SVG, PNG, and PDF output with configurable themes and dimensions.

Is Mermaid free to use?+

Yes. Mermaid is open source under the MIT license. It is free for personal, commercial, and open-source use. The live editor at mermaid.live is also free.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets