Complete Guide to Mermaid Diagrams

Learn how to create professional diagrams using simple text-based syntax

Advertisement

What is Mermaid?

Mermaid is a JavaScript-based diagramming and charting tool that uses Markdown-inspired text definitions to create and modify diagrams dynamically. It's an open-source project that allows you to generate diagrams from simple text descriptions.

Instead of using complex drawing tools, you write code-like syntax that describes your diagram, and Mermaid renders it as a visual diagram. This approach makes diagrams version-controllable, easy to update, and perfect for documentation.

Mermaid integrates seamlessly with documentation platforms, wikis, and markdown files, making it a favorite tool among developers and technical writers.

Why Use Mermaid?

  • Version Control: Diagrams are text files, so they can be tracked in Git alongside your code
  • Quick Updates: Change a few lines of text instead of redrawing entire diagrams
  • Consistency: Mermaid automatically handles layout and styling, ensuring consistent diagrams
  • No Design Tools Required: No need for Visio, Lucidchart, or other expensive tools
  • Documentation as Code: Keep diagrams in the same repository as your documentation
  • Cross-Platform: Works in browsers, Node.js, and integrates with many platforms
  • Free and Open Source: No licensing costs, active community support
  • Multiple Diagram Types: Supports flowcharts, sequence diagrams, class diagrams, and more
Advertisement

Supported Diagram Types

Mermaid supports a wide variety of diagram types to cover different documentation needs:

Flowchart

Visualize workflows, processes, and decision trees with nodes and edges.

flowchart TD
    A[Start] --> B{Decision}
    B -->|Yes| C[Process]
    B -->|No| D[Alternative]
    C --> E[End]
    D --> E

Use Case: Process flows, algorithms, decision logic

Sequence Diagram

Show interactions between different actors or systems over time.

sequenceDiagram
    participant User
    participant API
    participant DB
    User->>API: Request data
    API->>DB: Query
    DB-->>API: Results
    API-->>User: Response

Use Case: API interactions, system communication, user flows

Class Diagram

Model object-oriented systems with classes, attributes, and relationships.

classDiagram
    class Animal {
        +String name
        +int age
        +makeSound()
    }
    class Dog {
        +bark()
    }
    Animal <|-- Dog

Use Case: Software architecture, OOP design, database schemas

State Diagram

Represent states and transitions in a system or process.

stateDiagram-v2
    [*] --> Idle
    Idle --> Loading: Start
    Loading --> Success: Complete
    Loading --> Error: Fail
    Success --> [*]
    Error --> Idle: Retry

Use Case: State machines, lifecycle management, UI states

Entity Relationship Diagram

Model database structures and relationships between entities.

erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ LINE_ITEM : contains
    CUSTOMER {
        int id
        string name
        string email
    }

Use Case: Database design, data modeling, system architecture

Gantt Chart

Plan and visualize project schedules and timelines.

gantt
    title Project Timeline
    dateFormat YYYY-MM-DD
    section Phase 1
    Design :a1, 2024-01-01, 30d
    Development :a2, after a1, 45d

Use Case: Project planning, sprint timelines, roadmaps

Pie Chart

Show proportional data and percentages visually.

pie title Distribution
    "Category A" : 42
    "Category B" : 30
    "Category C" : 28

Use Case: Survey results, market share, resource allocation

Git Graph

Visualize Git branching strategies and commit history.

gitGraph
    commit
    branch develop
    checkout develop
    commit
    checkout main
    merge develop

Use Case: Git workflow documentation, branching strategies

Advertisement

Getting Started with Mermaid

1

Choose Your Diagram Type

Start by deciding which diagram best represents what you want to show. Each diagram type starts with a specific keyword like 'flowchart', 'sequenceDiagram', or 'classDiagram'.

2

Write the Text Syntax

Use Mermaid's simple syntax to describe your diagram. The syntax is intuitive and reads almost like natural language. For example, 'A --> B' creates an arrow from A to B.

3

Preview Your Diagram

Use our online viewer or any Mermaid-compatible tool to see your diagram rendered in real-time. Make adjustments as needed until you're satisfied.

4

Export and Share

Export your diagram as SVG or PNG for use in presentations, or share a URL with your team. You can also embed Mermaid directly in Markdown files.

Best Practices

  • Keep diagrams focused on a single concept or workflow
  • Use meaningful labels that describe the actual business logic
  • Break complex diagrams into smaller, interconnected diagrams
  • Add comments using %% to explain complex sections
  • Use consistent naming conventions throughout your diagrams
  • Test your diagrams in the target environment before finalizing
  • Include direction hints (TD, LR) to control layout when needed
  • Use subgraphs to group related nodes in flowcharts
  • Leverage styling options sparingly to maintain readability
  • Version control your diagram source files alongside your code

Common Use Cases

Software Documentation

Document system architecture, API flows, and component interactions alongside your code.

Project Planning

Create Gantt charts for sprint planning, project timelines, and resource allocation.

Technical Proposals

Visualize proposed solutions, system designs, and architectural decisions.

User Journeys

Map out user flows, customer experiences, and interaction patterns.

Database Design

Model entity relationships, schema structures, and data dependencies.

Process Documentation

Document business processes, workflows, and standard operating procedures.

Educational Materials

Create clear, version-controlled diagrams for tutorials and technical courses.

API Documentation

Illustrate request/response flows, authentication sequences, and endpoint interactions.

Additional Resources

Frequently Asked Questions

Common questions about using the Mermaid Viewer and creating diagrams

Is this Mermaid editor really free?
Yes, completely free! You can create unlimited diagrams, export to SVG/PNG, share via URL, and use all features without any sign-up or payment required. The tool is supported by non-intrusive advertising.
Do I need to install anything to use this editor?
No installation needed! This is a web-based tool that runs entirely in your browser. Just visit the site and start creating diagrams immediately. Works on desktop, tablet, and mobile devices.
How do I save my diagrams?
There are several ways to save your work: 1) Export as SVG or PNG using the export buttons, 2) Share via URL - the diagram code is encoded in the URL so you can bookmark or share it, 3) Copy the text code and save it in your own text files or documentation, 4) Upload/download .mmd or .mermaid files directly.
Can I use these diagrams in my documentation?
Absolutely! Export your diagrams as SVG (scalable) or PNG images and use them in any documentation, presentations, or websites. The exported images are yours to use freely. You can also embed the Mermaid code directly in platforms that support Mermaid like GitHub, GitLab, or Notion.
What's the difference between SVG and PNG export?
SVG (Scalable Vector Graphics) files maintain quality at any size and are ideal for documentation and web use. They're also editable. PNG files are raster images good for presentations and quick sharing but lose quality when resized. Use SVG when possible for best results.
My diagram isn't rendering - what's wrong?
Check for syntax errors in your Mermaid code. Common issues include: unclosed quotes, missing colons or semicolons, incorrect node IDs, or unsupported syntax. The error message usually indicates where the problem is. Try simplifying your diagram to identify the issue.
Can I collaborate with others on diagrams?
While real-time collaboration isn't built-in, you can easily share diagrams by sending the URL (which contains your diagram code) to others. They can then view, edit, and share their version back. The text-based nature of Mermaid also makes it perfect for version control systems like Git.
Does this work offline?
The initial load requires an internet connection, but once loaded, basic editing features work offline. However, some features like exporting might require connectivity. For guaranteed offline use, consider downloading Mermaid CLI or using a local Mermaid setup.
How do I learn Mermaid syntax?
Start with our comprehensive Mermaid Guide which covers all diagram types with examples. Use the Templates panel for quick starts with common patterns. The official Mermaid documentation at mermaid.js.org is also excellent. Each diagram type landing page on this site includes detailed how-to guides and best practices.
Can I customize the appearance of my diagrams?
Yes! Diagrams follow the site theme: switch between light and dark with the Theme button in the top bar and the diagram re-renders with Mermaid's matching theme. For more advanced customization, Mermaid supports custom themes and styling through the %%{init:...}%% directive. You can define colors, fonts, and other visual properties.
What diagram types are supported?
This editor supports all major Mermaid diagram types: Flowcharts (process flows), Sequence Diagrams (interactions), Class Diagrams (OOP structure), State Diagrams (state machines), ER Diagrams (database models), Gantt Charts (timelines), Pie Charts, Git Graphs, User Journey maps, and more.
Is my diagram data private?
Your diagram code is never sent to our servers. All rendering happens client-side in your browser. When you share via URL, the code is encoded in the URL itself. We don't store, track, or have access to your diagram content.
Why should I use text-based diagrams instead of drawing tools?
Text-based diagrams offer several advantages: they're version-controllable (perfect for Git), quick to update (change a few lines instead of redrawing), consistent in style, searchable, lightweight, and can be generated programmatically. They're also easier to review in pull requests.
Can I embed Mermaid diagrams in my website?
Yes! You can include the Mermaid JavaScript library in your website and add Mermaid code blocks. Many platforms already support Mermaid natively including GitHub, GitLab, Notion, Obsidian, and various wiki systems. Check your platform's documentation for Mermaid support.
What's the maximum size diagram I can create?
While there's no hard limit, very large diagrams (>100 nodes) may render slowly depending on your device. For complex systems, we recommend breaking them into multiple smaller, focused diagrams. This also makes them easier to understand and maintain.

Ready to Create Your First Diagram?

Try our free online Mermaid viewer and start creating professional diagrams in minutes.

Open Mermaid Viewer