Back to Blog

How to Natively Embed Mermaid Diagrams in Markdown

Published on June 5, 2026 • 5 min read

The killer feature of Mermaid.js isn't just its syntax; it's the fact that major platforms now support it natively. You don't need to export PNGs and upload them to your repository anymore.

Markdown Code Blocks

In standard Markdown, you use triple backticks to create a code block. To tell the parser that the block contains Mermaid syntax, you simply use the language identifier mermaid.

```mermaid
pie title Pets Adopted
  "Dogs" : 386
  "Cats" : 85
  "Rabbits" : 15
```
  

Where Does This Work?

The Workflow

When drafting complex diagrams, writing them directly in GitHub can be tedious because you have to constantly preview the file. A better workflow is to use a dedicated live editor like Mermaid Preview. Draft your diagram, see the real-time result, and when you're happy, copy the code and paste it into your Markdown file.

Recommended README Workflow

For repository documentation, keep the Mermaid block close to the paragraph it explains. A diagram that appears three screens away from the related explanation is harder to maintain and easier to ignore during review.

When to Export Instead

Native Mermaid blocks are ideal for developer platforms, but exported SVG or PNG files still make sense for slide decks, PDFs, product docs, or CMS tools that do not support Mermaid rendering. SVG is usually best for text-heavy diagrams because it remains crisp when zoomed. PNG is safer when the destination strips SVG files or when you need a simple image upload.

Common Markdown Mistakes

Try this in Mermaid Preview: paste the examples into the live editor, adjust the labels, then export SVG or PNG for your docs.

Open Mermaid Preview →

Related Resources