Ends Dec 1, PT
SciFig
Tutorials··Updated

Mermaid to Image: Export Diagrams (2026)

How to export Mermaid diagrams to PNG, SVG, and PDF with Mermaid Live Editor, mermaid-cli, VS Code, and CI, plus fixes for blurry, tiny, or cropped PNGs.

SciFig Team
SciFig Team
SciFig editorial team

To turn a Mermaid diagram into an image, export PNG or SVG from Mermaid Live Editor or the mmdc CLI.

Quick answer: for a one-off Mermaid to image export, paste the diagram into Mermaid Live Editor and download PNG or SVG from its Actions panel. For repeatable or batch exports, run mermaid-cli's mmdc command, which turns a .mmd or Markdown file into SVG, PNG, or PDF. When you need an editable, journal-ready version instead, SciFig FlowChart (flowcharts and diagrams) has AI redraw the diagram from your description, with every box, label and arrow editable, and exports SVG, PNG or PPTX.

Mermaid renders diagrams from text, which makes it excellent for documentation that lives in version control. Getting a file out of it — one you can drop into a manuscript, a slide, or a poster — is a separate step that trips people up, mostly because the default export is a PNG at screen resolution.

GoalMethodFormatsInstall neededCode leaves your machine?
One diagram, right nowMermaid Live Editor → Actions → PNG or SVGPNG, SVGNoYes, pasted into a hosted web page
Repeatable or batch exportmermaid-cli (mmdc)SVG, PNG, PDFNode.js, or run once with npxNo, renders locally
Preview while writing MarkdownVS Code extension or ObsidianPreview; some extensions export SVG/PNGEditor extensionNo
Always-current docsmmdc as a CI build stepSVG, PNG, PDFIn the pipelineStays in your CI
Editable, journal-ready redrawSciFig FlowChart: describe the diagram, or attach the Mermaid text as a .md file, and AI redraws it with every box, label and arrow editableSVG, PNG, JPG, PPTXNo, runs in the browserYes, uploaded to SciFig

The last row is a different kind of tool: instead of rendering your Mermaid code, AI redraws the diagram from your description as native SVG, so every node, label and arrow comes out as an element you can move, restyle and lay out to a journal's conventions. It is free to start, no card required, with 150 credits on your first day, and editing and SVG/PNG/PPTX export are free.

A Mermaid flowchart shown as source text beside its rendered SVG output (Figure generated with SciFig)
A Mermaid flowchart shown as source text beside its rendered SVG output (Figure generated with SciFig)

The Command Line Route

The official tool is @mermaid-js/mermaid-cli, which exposes an mmdc command:
npm install -g @mermaid-js/mermaid-cli
 
mmdc -i diagram.mmd -o diagram.svg          # vector, preferred
mmdc -i diagram.mmd -o diagram.pdf          # vector PDF
mmdc -i diagram.mmd -o diagram.png -s 3     # raster at 3x scale
Always prefer SVG or PDF. Both are vector, so text stays sharp at any size. Use PNG only when a destination cannot accept vector, and then set an explicit scale factor — the default resolution is too low for print.
FormatVectorGood forAvoid when
SVGYesWeb, further editing, most journalsTarget requires EPS
PDFYesManuscripts, print, slidesYou need to edit in a browser tool
PNGNoChat, wikis, quick previewsPrint or any scaling
mmdc also reads Markdown. mmdc -i notes.md -o notes-rendered.md renders every mermaid code block in the file to an image and writes a copy of the Markdown that points at those images — handy for a README or a lab notebook full of diagrams.

See AI Scientific Figure Generation in Action

Watch how researchers create publication-ready scientific figures from text descriptions.

Explore the Tool

How to export Mermaid to PNG (and fix blurry, tiny or cropped output)

To produce a PNG file from a Mermaid diagram, give mmdc an output name ending in .png. The PNG is trimmed to the diagram itself, and its size comes from two settings: the page width the diagram is laid out in, and the scale factor. Most "bad PNG" complaints trace back to one of the fixes below.
Blurry PNG: raise the scale. -s multiplies the pixel density without changing the layout. -s 2 suits slides, -s 3 or -s 4 suits print.
mmdc -i diagram.mmd -o diagram.png -s 3
Tiny text in a wide diagram: widen the page. -w sets the page width (default 800 px) and -H the page height (default 600 px). Mermaid shrinks a wide diagram to fit the page, so a long left-to-right flowchart can come out with unreadable labels. A wider page keeps the labels at full size.
mmdc -i diagram.mmd -o diagram.png -w 1600 -s 2
Cropped or squeezed output: export SVG first. If labels are cut off or crowded, render SVG and open it in a browser. If the SVG looks right, the problem is page size or scale; if it looks wrong too, shorten the labels or switch direction (graph TD instead of graph LR).
White box behind the diagram: use a transparent background. -b sets the background for PNG and SVG (not PDF). The default is white.
mmdc -i diagram.mmd -o diagram.png -b transparent -s 3
Wrong font or theme: put it in a config file. -c loads a JSON configuration for Mermaid, so every diagram you export shares one font and theme. -t picks a built-in theme (default, forest, dark, neutral) for a single run.
{
  "theme": "neutral",
  "themeVariables": { "fontFamily": "Arial" }
}
mmdc -i diagram.mmd -o diagram.png -c config.json -s 3
Editor themes do not come along. A dark VS Code theme, Obsidian's dark mode or a theme picked in an editor's UI only changes how the preview looks. The exported file uses whatever theme is written in the diagram (an init line or front matter) or passed to mmdc. If the export looks different from your preview, write the theme into the diagram.
mmdc will not install: run it with npx. Global installs fail on locked-down machines. npx downloads the CLI into a cache and runs it once, with no global install. The first run also downloads a headless browser, so it takes a few minutes.
npx -y @mermaid-js/mermaid-cli -i diagram.mmd -o diagram.png -s 3

Timeline and Sequence Diagram Examples

These minimal examples export with the same commands. Save each as a .mmd file.
Mermaid timeline example (image/PNG):
timeline
    title Research project timeline
    2024 : Grant awarded
    2025 : Pilot study : Data collection
    2026 : Analysis : Manuscript submitted
mmdc -i timeline.mmd -o timeline.png -s 3
Mermaid sequence diagram example:
sequenceDiagram
    participant R as Researcher
    participant S as Sequencing core
    participant P as Analysis pipeline
    R->>S: Submit samples
    S-->>R: Raw reads
    R->>P: Run QC and alignment
    P-->>R: Results table
mmdc -i sequence.mmd -o sequence.svg

Other Export Routes

Mermaid Live Editor. The browser editor exports SVG and PNG directly from its Actions panel and is the fastest option for a one-off diagram, though it means pasting your diagram into a hosted service — a consideration if the content is sensitive.
VS Code. The Markdown Preview Mermaid Support extension renders diagrams inline, and the Mermaid Editor extension adds direct SVG and PNG export. Convenient while drafting.
CI pipelines. Because mmdc is a CLI, diagram rendering can be a build step. A common pattern is committing .mmd sources and generating images during documentation builds, so the rendered output never goes stale relative to the source.
- run: npm install -g @mermaid-js/mermaid-cli
- run: mmdc -i docs/architecture.mmd -o docs/architecture.svg
A CI pipeline diagram showing Mermaid source committed to the repository and images generated during the documentation build (Figure generated with SciFig)
A CI pipeline diagram showing Mermaid source committed to the repository and images generated during the documentation build (Figure generated with SciFig)

Exporting from Obsidian, VS Code and Into Papers or Slides

Obsidian. Obsidian renders mermaid code blocks in the note preview, but it has no built-in button to save a single diagram as an image file. Exporting the note to PDF carries the diagram along. For a standalone PNG or SVG, copy the code block into Mermaid Live Editor, or save it as a .mmd file and run mmdc. Because mmdc reads Markdown, you can also point it at the note itself.
VS Code and Markdown previews. A Mermaid preview extension shows the diagram as you type. To export a Mermaid diagram in Markdown as PNG in VS Code, use an export-capable extension, or keep the diagram in a .mmd file next to your Markdown and render it with mmdc from the integrated terminal.
Papers and slides. Export SVG (or PDF for LaTeX), not PNG. In PowerPoint, insert the SVG as a picture; recent versions can convert it to shapes so you can recolor boxes. In Illustrator or Inkscape, open the SVG to adjust spacing, fonts and arrowheads before placing it in the manuscript. Use PNG at -s 3 or higher only when a submission system rejects vector files.
The same Mermaid flowchart rendered in the default and neutral themes, showing the difference in print legibility (Figure generated with SciFig)
The same Mermaid flowchart rendered in the default and neutral themes, showing the difference in print legibility (Figure generated with SciFig)

Controlling Appearance

Mermaid's defaults are built for documentation, not for publication. Three levers matter:

  • Themes. %%{init: {'theme':'neutral'}}%% at the top of the file. neutral and base print better than the default.
  • Fonts. Set fontFamily in the init block so the diagram matches the surrounding document.
  • Direction. graph LR versus graph TD changes the aspect ratio, which matters more than it sounds when fitting a diagram into a column.

A research process flowchart with a neutral theme and a print font:

%%{init: {'theme':'neutral', 'themeVariables': {'fontFamily':'Helvetica'}}}%%
graph LR
  A[Sample collection] --> B[Extraction]
  B --> C[Sequencing]
  C --> D[Analysis]

When Mermaid Is the Wrong Tool

Mermaid computes layout automatically, and you get limited control over it. That is a feature for documentation and a limitation for scientific figures where composition carries meaning.

Mermaid fitsSwitch to SciFig FlowChart or a vector editor
Documentation that lives in version controlA manuscript figure that must match a journal's visual conventions
Diagrams regenerated on every buildPrecise spatial arrangement you control box by box
Automatic layout is good enoughPositions that reflect real relationships, such as anatomical position or temporal sequence
Text-only source that diffs in reviewCo-authors who edit the figure visually rather than in code

A workable compromise: generate the structure in Mermaid, export SVG, then finish in a vector editor — accepting that the finishing step breaks regeneration.

A Mermaid auto-layout diagram beside the same content rearranged manually for a manuscript figure (Figure generated with SciFig)
A Mermaid auto-layout diagram beside the same content rearranged manually for a manuscript figure (Figure generated with SciFig)
Another route is a redraw in SciFig FlowChart. Describe the diagram in plain language, or attach your Mermaid text as a .md file, and the text to diagram generator has AI draw an editable version as native SVG, where every box, label and arrow can be moved and restyled directly. For an interaction like the sequence example above, the sequence diagram generator does the same for participants and messages. It is free to start with 150 credits on your first day, and editing, saving and exporting SVG, PNG or PPTX are free. If you are weighing template-based design tools for the same job, see our Canva alternatives for diagrams.

Tip

Commit the .mmd source alongside the exported image. The source diffs meaningfully in review and regenerates when things change; the image is what people actually look at. Keeping only one of the two costs you either reviewability or convenience.

Create Scientific Figures Now

Describe your scientific figure in natural language — get publication-ready illustrations in minutes.

Try Free
For publication figures beyond diagrams, text to figure handles illustrations. See our guide to visualizing research for the broader workflow.

Related reading: Visualize Research with AI Text-to-Figure, 10 Best Scientific Illustration Tools in 2026, 7 Free Canva Alternatives for Scientific Diagrams (2026).

FAQ

Keep going

Recommended resources

Templates, tools, and further reading for your research

Call to action background

Ready to start?

Publication-ready scientific figures, in minutes

Start Creating Free

Free to start · No credit card required · Built for researchers