Mermaid.js Tutorial: Complete Beginner's Guide

What is Mermaid.js? Mermaid.js is a JavaScript-based diagramming tool that lets you create diagrams and visualizations using text and code, similar to Markdown. Instead of dragging and dropping shapes in a GUI, you write simple text definitions that render into professional diagrams—flowcharts, sequence diagrams, class diagrams, Gantt charts, and more.

Mermaid.js has become the standard for technical documentation, especially in developer communities. It's supported natively by GitHub, GitLab, Notion, and many other platforms, making it easy to embed diagrams directly in your documentation.

Why Learn Mermaid.js?

Getting Started: Your First Flowchart

The most common diagram type is the flowchart. Here's a simple example:

flowchart TD
    Start --> Stop

This creates a basic flowchart with two nodes: "Start" and "Stop", connected by an arrow.

Adding Nodes and Connections

flowchart TD
    A[Start] --> B{Is it working?}
    B -->|Yes| C[Great!]
    B -->|No| D[Debug]
    D --> B
    C --> E[End]

Syntax explained:

Creating Sequence Diagrams

Sequence diagrams show interactions between components:

sequenceDiagram
    participant A as Client
    participant B as Server
    participant C as Database
    
    A->>B: Request Data
    B->>C: Query
    C-->>B: Results
    B-->>A: Response

Key syntax:

Other Popular Diagram Types

Class Diagram

classDiagram
    class User {
      +String name
      +String email
      +login()
      +logout()
    }
    class Order {
      +Int id
      +Date date
      +placeOrder()
    }
    User --> Order : places

Gantt Chart

gantt
    title Project Timeline
    dateFormat YYYY-MM-DD
    section Planning
    Requirements :a1, 2026-01-01, 7d
    Design      :a2, after a1, 5d
    section Development
    Coding      :a3, after a2, 14d
    Testing     :a4, after a3, 7d

Mermaid.js Best Practices

Pro Tip: Use %%{init: {'theme': 'dark'}}%% at the start of your diagram to set the theme.

Common Mistakes to Avoid

AI-Powered Mermaid Creation

Learning Mermaid syntax takes time. AI-powered tools like SmoothMermaid let you describe diagrams in plain English and automatically generate the Mermaid code.

For example, type: "Show a user registration flow with email verification" and get instant Mermaid code:

flowchart TD
    A[User enters email] --> B{Email valid?}
    B -->|Yes| C[Send verification]
    C --> D[User clicks link]
    D --> E[Account activated]
    B -->|No| F[Show error]
    F --> A

Next Steps

Now that you understand the basics:

  1. Practice with simple flowcharts
  2. Try different diagram types
  3. Integrate diagrams into your documentation
  4. Use AI tools to speed up creation

Start Creating Mermaid Diagrams

Ready to create professional diagrams without learning complex syntax? Try SmoothMermaid's AI-powered editor—describe your diagram in plain English and watch it appear instantly.

Try AI-Powered Mermaid →