Quickstart
This guide will help you create and render your first Mermaid diagram. You’ll learn the basic workflow for integrating Mermaid into your project.Step 1: Install Mermaid
First, install Mermaid in your project:Step 2: Create your HTML file
Create an HTML file with a div element that will contain your diagram. Use the classmermaid to mark elements for automatic rendering:
index.html
The
mermaid.initialize() function configures Mermaid. Setting startOnLoad: true tells Mermaid to automatically render all diagrams when the page loads.Step 3: Initialize and render
If you’re using Mermaid in a JavaScript application, here’s how to initialize and render diagrams programmatically:1
Import Mermaid
Import the Mermaid library in your JavaScript file:
app.js
2
Initialize Mermaid
Configure Mermaid with the Common configuration options:
initialize() function. This should be done before rendering:app.js
startOnLoad: Automatically render diagrams on page load (default:true)theme: Visual theme ('default','dark','forest','neutral')logLevel: Console logging level ('debug','info','warn','error','fatal')
3
Render diagrams
For automatic rendering, Mermaid will find all elements with the class For manual rendering of a specific diagram:
mermaid and render them:app.js
app.js
4
View your diagram
Open your HTML file in a browser. You should see your diagram rendered!
Example: Complete application
Here’s a complete example showing different ways to use Mermaid:complete-example.html
Common patterns
Parsing diagrams
Validate diagram syntax without rendering:Error handling
Handle rendering errors gracefully:Detecting diagram types
Next steps
Now that you’ve created your first diagram, explore more advanced topics:Diagram syntax
Learn the syntax for different diagram types
Configuration
Customize themes, styling, and behavior
API reference
Explore the complete Mermaid API
Examples
Browse real-world diagram examples