# mermaid-cli

> Command-line tool (mmdc) that renders Mermaid diagram definitions and Markdown files with Mermaid code blocks to SVG, PNG, or PDF.

Stars: 5.2k · Language: JavaScript · License: MIT · Categories: Dev Tools

- Repository: https://github.com/mermaid-js/mermaid-cli
- Page: https://www.trmn.sh/tools/mermaid-cli

## Install

- npm: `npm install -g @mermaid-js/mermaid-cli`
- Docker: `docker pull minlag/mermaid-cli`
- npx: `npx -p @mermaid-js/mermaid-cli mmdc -h`

## Overview

mermaid-cli is the command-line interface for the Mermaid diagramming library. Its executable, `mmdc`, takes a Mermaid definition file (.mmd) as input and writes an SVG, PNG, or PDF file. For example, `mmdc -i input.mmd -o output.svg` renders a diagram, and `mmdc -i input.mmd -o output.png -t dark -b transparent` produces a PNG with a dark theme and transparent background. Input can also be piped from stdin with `--input -`, such as from a heredoc.

It can also process Markdown files. Running `mmdc -i readme.template.md -o readme.md` finds the mermaid code blocks, renders each one to an SVG file, and replaces the blocks with image references in the output Markdown. Accessibility title and description set in the diagram (`accTitle`, `accDescr`) become the image title and alt text. The README describes this Markdown support as basic.

Other options include `--cssFile` to inline custom CSS (for example, to animate an SVG) through Mermaid's `themeCSS` setting, and `--size` to try to produce a PNG of a given size. Custom icon packs can be loaded either from npm packages with `--iconPacks` or from URLs and `file://` URIs with `--iconPacksAndUrls`. A Node.js API exposes a `run(input, output, options)` function, but it isn't covered by semver, because the package follows Mermaid's versioning.

It suits developers, documentation authors, and CI pipelines that need to generate diagram images from text definitions. Besides the global npm install, it can be installed locally, run through `npx -p @mermaid-js/mermaid-cli mmdc`, or run from Docker or Podman images that read input files from `/data`. The Homebrew install is no longer supported and only provides an old version.

### Installation

```bash
# via npm
npm install -g @mermaid-js/mermaid-cli
```

```bash
# via Docker
docker pull minlag/mermaid-cli
```

```bash
# via npx
npx -p @mermaid-js/mermaid-cli mmdc -h
```

## Alternatives

- [DocToc](https://www.trmn.sh/tools/doctoc.md): Node.js CLI that generates and updates tables of contents in Markdown files, with anchor links compatible with GitHub, GitLab, Bitbucket, Ghost and nodejs.org. (JavaScript, 4.5k stars)
- [Plop](https://www.trmn.sh/tools/plop.md): Micro-generator framework that runs inquirer prompts and Handlebars templates from a plopfile to create consistent files from the terminal. (JavaScript, 7.7k stars)
- [np](https://www.trmn.sh/tools/np.md): Interactive release tool for npm packages that checks the working tree, runs tests, bumps versions, creates tags, publishes, and pushes to Git. (JavaScript, 7.7k stars)
- [release-it](https://www.trmn.sh/tools/release-it.md): Generic CLI for automating releases: version bumps, git commit/tag/push, changelogs, GitHub/GitLab releases, and npm publishing, with hooks and plugins. (JavaScript, 9.1k stars)
- [terminalizer](https://www.trmn.sh/tools/terminalizer.md): Terminal session recorder that generates animated GIF images from command-line sessions (JavaScript, 16.2k stars)

---

Canonical: https://www.trmn.sh/tools/mermaid-cli
