Skip to main content

Overview

Mermaid can be integrated into various frameworks and build systems. This guide provides practical integration patterns for popular frameworks, along with examples and best practices from the source code.

Module formats

Mermaid is available in multiple module formats:
  • ESM (recommended): mermaid.esm.min.mjs
  • UMD: mermaid.min.js
  • Tiny version: Approximately half the size, without Mindmap, Architecture, KaTeX, or lazy loading
From usage.md:66:
Or with npm:

React integration

Using hooks

Usage in React component

Class component version

Vue integration

Vue 3 composition API

Vue 2 options API

Angular integration

Mermaid service

Mermaid component

Usage in Angular template

Svelte integration

Webpack integration

From usage.md:227, Mermaid fully supports webpack:

In your application

See the working demo.

Vite integration

Usage with Vite

Next.js integration

Client-side only component

Usage in Next.js page

Markdown renderers

With marked

From usage.md:303:

With markdown-it

CDN usage

From usage.md:14:
Mermaid automatically renders diagrams with class="mermaid" when startOnLoad is true (default). Set startOnLoad: false for manual control.

Best practices

Initialize once

Use unique IDs

From mermaid.ts:155:

Handle bindFunctions

From usage.md:279:

Prevent re-rendering

From mermaid.ts:165, Mermaid marks processed elements:
In your framework: