Support
Diagrams

How to Export a Mermaid Diagram to PNG, SVG or PDF

November 19, 2026 · 5 min read

Mermaid diagrams live as text, but a slide deck, a PDF report or a wiki page often wants an image. You can get one without installing anything: paste the code into the Hexabench Mermaid editor, check the preview, and download PNG, SVG or PDF. This guide says which format to pick, what each export contains, and when the command-line tool is the better route.

Quick answer: three steps in the editor

  1. Paste your Mermaid code into the editor, or open a .mmd file. The preview updates as you type.
  2. Check the preview. If there is a syntax error, the page shows the line number and keeps the last good render.
  3. Use the export bar under the preview: Export SVG, Export PNG (pick 1x, 2x or 3x first), Export PDF, or Copy image.

Try it with a small diagram:

flowchart TD
    A[Start] --> B{Is it valid?}
    B -->|Yes| C[Process data]
    B -->|No| D[Show error]
    C --> E[Save result]
    D --> A
    E --> F[End]

Open in editor: a flowchart

Which format should I use?

FormatUse it forWhat you get
SVGDocs, web pages, anything that should scaleThe rendered vector markup, with a solid background
PNGSlides, chat, issue trackersA raster image at 1x, 2x or 3x the diagram's size
PDFReports and documentsOne page sized to the diagram; the diagram is an image inside the PDF
Copy imagePasting straight into a documentA PNG on your clipboard

Export Mermaid to PNG

A PNG is only as sharp as its pixel size, so choose the scale before you click Export PNG. 1x is the diagram at its natural size, 2x suits most screens, and 3x is the one to use for slides and print. The scale menu applies to PNG and Copy image; it does not change the PDF.

Export Mermaid to SVG without mermaid-cli

Export SVG downloads the rendered markup straight from the browser, with no Node, no headless browser and no command line. The background colour is baked in so the file is not transparent on transparent. Mermaid flowcharts draw their labels as HTML inside the SVG, and some vector editors do not show such labels, so open the file in the program you will use before you rely on it. To make the file smaller, run it through the SVG Optimizer.

Export Mermaid to PDF

Export PDF puts the diagram on a single page sized to it, in landscape or portrait to suit its shape. The diagram is drawn to a canvas at 2x and placed on the page as an image, so text in the PDF is not selectable and the sharpness is fixed by that resolution. If you need a vector PDF or selectable text, use mermaid-cli (below).

Backgrounds and themes

The editor has four Mermaid themes: default, dark, neutral and forest. The export follows the theme you chose: exports have a solid background, white for the three light themes and the dark panel colour for the dark theme. There is no transparent option in the editor.

When to use mermaid-cli instead

The browser is the quickest way to export one diagram. For many diagrams, for builds that must be repeatable, or for a transparent background, use the official command-line tool, mermaid-cli. Its README says it generates SVG, PNG or PDF files and shows a transparent PNG like this:

npx -p @mermaid-js/mermaid-cli mmdc -i input.mmd -o output.png -t dark -b transparent

Do I need to export at all?

GitHub renders fenced code blocks tagged mermaid in Markdown files itself, so a diagram in a README needs no export. Copy the diagram text between the fences. To see the same text with a live preview first, open it in the editor. Looking for syntax? See the Mermaid cheat sheet and the Mermaid diagram examples.

Frequently asked questions

How do I convert Mermaid to PNG online?
Paste the code into the Hexabench Mermaid editor, choose 1x, 2x or 3x, and click Export PNG. It is rendered in your browser and downloads as a .png file.
How do I export a Mermaid diagram to PDF?
Click Export PDF in the editor. You get a one-page PDF sized to the diagram, in landscape or portrait to suit its shape. The diagram is an image inside the PDF.
Is the PDF vector or an image?
An image. The editor draws the diagram to a canvas at 2x and places it on the page, so text is not selectable and quality is fixed by that resolution. For a vector PDF use mermaid-cli.
How do I get an SVG from Mermaid without mermaid-cli?
Click Export SVG. It downloads the rendered markup with a solid background colour baked in.
Can I export a Mermaid diagram with a transparent background?
Not from this editor: exports always have a solid background. mermaid-cli can make a transparent PNG; its README shows mmdc -i input.mmd -o output.png -t dark -b transparent.
Why does my exported PNG look blurry?
A PNG is only as sharp as its pixel size. Choose 3x before exporting, especially for slides and print.
Is my diagram sent to a server when I export?
No. Rendering and export happen in your browser. There is no upload step.
Can I export a whole Markdown file with several Mermaid diagrams?
Not in one go. The editor handles one diagram at a time (a Markdown file opens with its first mermaid block). Export each diagram, or use a Markdown-to-PDF tool that supports Mermaid.

Open the Mermaid editor → · Back to Blog