Embedding Mermaid in Markdown: render it anywhere
The power of Mermaid is that it's pure text. A diagram is just a string — you can paste it into a GitHub README, a Notion database, a GitLab wiki, or your Sphinx docs site, and it renders without extra setup. But each platform has its quirks. This guide shows you exactly how to embed Mermaid in every major platform and avoid common pitfalls.
Mermaid in GitHub (README, issues, PRs)
GitHub natively renders Mermaid in Markdown. Just wrap your diagram in a triple-backtick fence with the mermaid language specifier:
```mermaid
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Continue]
B -->|No| D[Stop]
```
Supported in:
- README files (
*.md) - Issues and issue comments
- Pull request descriptions and review comments
- GitHub Discussions
- GitHub Pages (Jekyll, Hugo, etc. via
mermaid.min.js)
Quirks:
- Very large diagrams (300+ nodes) may fail silently. Keep diagrams under 150 nodes for reliability.
- Dark mode support is automatic; no manual styling needed.
- GitHub doesn't support all Mermaid directives (e.g.,
%%{init: {...}}%%for custom configs has limited support in some versions). Test on your version first.
Example in a PR description:
## What this PR does
Adds a new payment flow:
```mermaid
graph LR
A[User] -->|Clicks Pay| B[Stripe Form]
B -->|Token| C[Backend API]
C -->|Webhook| D[Update DB]
D -->|Success| A
```
This replaces the old hardcoded payment handler.
Mermaid in GitLab (Wiki, issues, Markdown files)
GitLab also natively supports Mermaid with the same fence syntax:
```mermaid
flowchart TD
A[Build] --> B[Test]
B --> C{Pass?}
C -->|Yes| D[Deploy]
C -->|No| E[Notify]
```
Supported in:
- Repository Markdown files (
.md) - Wiki pages
- Issues and merge requests
- Snippets
Quirks:
- The
initdirective works more reliably than on GitHub, so you can include config:
```mermaid
%%{init: {'theme': 'dark', 'flowchart': {'maxWidth': 500}}}%%
flowchart TD
...
```
Mermaid in Notion
Notion renders Mermaid natively inside code blocks — no plugin or embed needed:
- Type
/codeto insert a code block. - Set the block's language to Mermaid (search the language dropdown).
- Paste your Mermaid source, then use the block's Split or Preview toggle (top-right of the block) to show the rendered diagram alongside or instead of the code.
The diagram re-renders as you edit the source, follows your page's light/dark theme, and travels with the page when you duplicate or share it.
When you want a static image instead — for a page cover, a PDF export, or a place where the live block won't do — export the diagram to PNG/SVG from MermaidCreator and upload it. It isn't editable in Notion, but it always renders crisply.
Mermaid in Sphinx and MkDocs (Python docs)
Both Sphinx (Python docs) and MkDocs (static site generator) support Mermaid via plugins.
Sphinx (with sphinxcontrib-mermaid)
Install:
pip install sphinxcontrib-mermaid
Add to conf.py:
extensions = ["sphinxcontrib.mermaid"]
Then use in .rst files:
.. mermaid::
graph TD
A[API Endpoint] --> B[Handler]
B --> C[Response]
MkDocs (with pymdown-extensions)
Add to mkdocs.yml:
markdown_extensions:
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_code_format
Then use in Markdown:
```mermaid
graph LR
A[Input] --> B[Process] --> C[Output]
```
Mermaid in Jekyll and Hugo (static site generators)
Jekyll (with mermaid gem or CDN)
Add to your Gemfile:
gem "jekyll-mermaid"
Or load from CDN in your layout:
<script async src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
Then use Mermaid code blocks in Markdown as usual.
Hugo
Add the Mermaid script to your site's base template (layouts/baseof.html):
{{ with resources.Get "js/mermaid.min.js" }}
<script async src="{{ .RelPermalink }}"></script>
{{ end }}
Then use Mermaid fenced code blocks in Markdown content.
Mermaid in Jira and Confluence (Atlassian)
Confluence
Use the official Mermaid for Confluence plugin (available in the Atlassian Marketplace).
Once installed, create a macro in Confluence:
{mermaid}
graph TD
A[Task] --> B[Subtask]
B --> C[Done]
{mermaid}
Jira
Jira doesn't have native Mermaid support, but you can:
- Embed images exported from MermaidCreator.
- Link to external Mermaid diagrams in attached documentation.
- Use a custom Jira add-on for Mermaid rendering.
Platform comparison table
| Platform | Native Support | Syntax | Dark Mode | Config Directives | Notes |
|---|---|---|---|---|---|
| GitHub | ✅ Yes | ```mermaid | Auto | Limited | Works in README, issues, PRs |
| GitLab | ✅ Yes | ```mermaid | Auto | ✅ Full | Works in wiki, issues, MRs |
| Notion | ✅ Yes | Code block → Mermaid | Auto | Limited | Toggle the block's Preview/Split view |
| Sphinx | ✅ Plugin | .. mermaid:: | ✅ Yes | ✅ Yes | Requires sphinxcontrib-mermaid |
| MkDocs | ✅ Plugin | ```mermaid | ✅ Yes | ✅ Yes | Requires pymdown-extensions |
| Confluence | ✅ Plugin | {mermaid}...{mermaid} | ✅ Yes | ✅ Yes | Requires Atlassian add-on |
| Jira | ❌ No | N/A | N/A | N/A | Use image exports or links |
Best practices for portable diagrams
- Use standard Mermaid syntax — avoid features that are new or niche. Test on your target platform.
- Keep diagrams readable at small sizes — many platforms render in sidebars or narrow columns.
- Use color sparingly — rely on shape and layout for clarity; color is a bonus.
- Test on light and dark themes — ensure labels are readable on both.
- Include a text fallback — if Mermaid rendering fails, provide a link to the diagram in the editor.
Example fallback in Markdown:
```mermaid
graph LR
A[Request] --> B[Response]
```
> Can't see the diagram? View it [here](/playground) or [as an image](/diagrams/request-response.png).
Example: embedding Mermaid in a multi-platform workflow
You write a diagram once in the MermaidCreator editor:
graph TD
A["Diagram in MermaidCreator"]
B["Export Mermaid code"]
C["Paste in GitHub README"]
D["Paste in Sphinx docs"]
E["Paste in Notion (as link or image)"]
A --> B
B --> C
B --> D
B --> E
That one diagram appears in your README, your docs site, and your project wiki — all from the same source. When you update the diagram, you update every instance.
FAQ
Can I embed Mermaid directly in HTML without a CDN?
Yes. Download mermaid.min.js and host it locally, or use npm install mermaid in a Node.js project.
Which Mermaid features work on all platforms? Flowcharts, sequence diagrams, class diagrams, state diagrams, ER diagrams, and Gantt charts. Newer formats (sankey, pie charts, mindmaps) may not render on older platform versions.
How do I style Mermaid diagrams across platforms?
Use the init config directive to set themes and colors. Most platforms support it, but GitHub has limited support — check their docs first.
Create your diagrams once in MermaidCreator at /playground, export the code, and paste it everywhere your team collaborates.
Related posts
Mermaid requirement diagram syntax: engineering specs made visual
Map software requirements with Mermaid's requirementDiagram. Link specs, components, and acceptance criteria in one view.
Mermaid Notes & Annotations: Document Diagram Intent & Context
Add clarity to diagrams with notes, comments, and annotations—best practices for labeling decisions, explaining asynchronous flows, and preventing ambiguity.