How to Export Mermaid Diagrams to PNG, SVG, and PDF

Published on November 28, 2026 • 3 min read

Mermaid diagrams are text, but slides, tickets, and chat messages need an image. You can get a PNG, SVG, or PDF in seconds in the browser, or automate it with the official command-line tool.

Fastest option: the free Mermaid to PNG converter exports PNG or SVG at up to 4x, with a transparent background if you need one.

Which format should you use?

FormatBest forWatch out for
SVGDocumentation sites, wikis, anything that needs to stay sharp at any zoom levelSome design and office apps do not render Mermaid's HTML labels (see below)
PNGSlack, Jira, email, Google Docs, slidesExport at 2x or 3x so it stays sharp on high-resolution screens
PDFPrinting and formal attachmentsNeeds the Mermaid CLI or your browser's print dialog

Method 1: Export in your browser

The fastest way needs no installation:

  1. Open Mermaid Preview and paste your Mermaid code.
  2. Click Export in the top bar.
  3. Choose Download PNG (rendered at 2x resolution), Download SVG, or Copy SVG code to paste straight into an HTML page or a design tool.

Rendering happens locally, so your diagram is never uploaded anywhere. The PNG uses a solid background that matches the current light or dark theme. If you need a transparent background, export SVG instead.

Mermaid Preview draws diagrams in its own green color scheme. To export with Mermaid's standard look instead, add a theme directive as the first line:

Export with a built-in Mermaid theme

The first line overrides the editor theme for this diagram only. Other built-in themes are neutral, forest, and dark.

%%{init: {'theme': 'default'}}%%
flowchart LR
  A[Write Mermaid] --> B[Preview]
  B --> C[Export PNG or SVG]

Method 2: The Mermaid CLI (mmdc)

For repeatable exports, scripts, and CI pipelines, use the official @mermaid-js/mermaid-cli package. It runs a headless browser to render diagrams, so the first install takes a moment.

npm install -g @mermaid-js/mermaid-cli

# SVG
mmdc -i diagram.mmd -o diagram.svg

# High-resolution PNG with a transparent background
mmdc -i diagram.mmd -o diagram.png -s 3 -b transparent

# PDF cropped to the diagram size
mmdc -i diagram.mmd -o diagram.pdf --pdfFit

# Dark theme
mmdc -i diagram.mmd -o diagram.png -t dark -b "#0b0e13"

Useful options:

To try it without a global install, run it through npx:

npx -p @mermaid-js/mermaid-cli mmdc -i diagram.mmd -o diagram.svg

Convert every diagram in a Markdown file

If you pass a Markdown file, mmdc renders each mermaid code block to a separate image file and writes a new Markdown file that references those images. This is useful for platforms that cannot render Mermaid themselves.

mmdc -i README.template.md -o README.md

Troubleshooting exports

Labels are missing when I open the SVG in another app

By default, Mermaid draws flowchart labels as HTML inside the SVG (using an element called foreignObject). Browsers display it correctly, but many tools, including some versions of Inkscape, PowerPoint, and other design apps, do not. Turn off HTML labels so Mermaid uses plain SVG text:

Flowchart with plain SVG text labels

With htmlLabels turned off, the exported SVG opens correctly in more design and office tools.

%%{init: {'flowchart': {'htmlLabels': false}}}%%
flowchart TD
  A[Design review] --> B{Approved?}
  B -->|Yes| C[Export SVG]
  B -->|No| A

The PNG is blurry

Export at a higher scale (-s 3 with the CLI), or use SVG wherever the destination supports it.

The fonts look different on another computer

An SVG references fonts by name, so a computer without that font falls back to a different one. Export a PNG when the exact look matters, or set a common font such as Arial in your Mermaid configuration.

The diagram is cut off or too small

Very wide diagrams scale down to fit. Switch the direction (LR to TD), split the diagram into smaller ones, or export SVG so readers can zoom in.

Try it in Mermaid Preview: Paste your diagram into the live editor and click Export to download a PNG or SVG. Nothing is uploaded.

Open the editor →

Related resources