Home/Docs/Mermaid Diagrams

Mermaid Diagrams

Documentation isn't always about writing text. Sometimes, a simple diagram explains an idea much faster than several paragraphs.

That's where Mermaid Diagrams are useful.

Mermaid lets you create diagrams and charts using plain text. Instead of designing diagrams in a separate application, you simply write a few lines of code inside your Markdown document, and a supported platform converts that code into a visual diagram.

Whether you're documenting an application, explaining an API, designing a database, or planning a project, Mermaid helps you create professional diagrams without leaving your Markdown file.

In this guide, you'll learn what Mermaid is, how it works, where it's supported, and how to create the most commonly used diagrams with practical examples.

If you're new to Markdown, read Markdown Basics, Markdown Syntax, and Markdown Code Blocks before continuing.

🟢 Practice as you read: Open the Markdown Editor — it renders Mermaid diagrams in live preview.

Open EditorDownload PDF

What Are Mermaid Diagrams?

Mermaid is a text-based diagramming tool that allows you to create diagrams using simple syntax.

Instead of drawing shapes with your mouse, you describe the diagram using text.

For example, this simple code:

flowchart TD
    Start --> Login
    Login --> Dashboard

can be rendered as a flowchart showing the journey from Start to Login and then to Dashboard.

This approach has several advantages:

  • Diagrams are easy to edit.
  • They can be stored alongside your Markdown files.
  • Changes can be tracked using Git.
  • Teams can collaborate without editing image files.
  • Documentation stays up to date because diagrams are created from text.

Because Mermaid diagrams are written as code, updating them is often much faster than recreating diagrams in traditional design software.

Why Use Mermaid Diagrams?

Many people create diagrams using design tools or image editors.

While those tools work well, updating diagrams later can become time-consuming.

Imagine changing the name of a process in a large flowchart. With an image editor, you might need to move shapes, reconnect arrows, and adjust spacing.

With Mermaid, you simply edit a few lines of text.

This saves time and keeps documentation easier to maintain.

Mermaid is commonly used for:

  • Software documentation
  • API documentation
  • Project planning
  • Database design
  • System architecture
  • Development workflows
  • Technical tutorials
  • Team documentation

Because diagrams are stored as text, they work well with version control systems like Git.

How Mermaid Works

Mermaid diagrams are written inside a code block.

Instead of specifying a programming language like html or javascript, you use mermaid.

Example:

```mermaid
flowchart TD
    Start --> End
```

When opened in a supported Markdown application, the code is automatically converted into a diagram.

If the platform doesn't support Mermaid, you'll simply see the code instead of the rendered diagram.

This is why it's important to know where Mermaid is supported before using it.

We'll cover platform compatibility later in this guide. See Markdown Code Blocks for fenced blocks and syntax highlighting.

Your First Mermaid Diagram

Let's create a very simple flowchart.

```mermaid
flowchart TD
    Start --> Login
    Login --> Dashboard
```

This diagram describes a basic login process.

If we draw it as a simple workflow, it looks like this:

Start
  │
  ▼
Login
  │
  ▼
Dashboard

Even with just three steps, it's much easier to understand the process visually than by reading a paragraph of text.

This is one of the biggest advantages of Mermaid diagrams.

Understanding Mermaid Syntax

Before creating larger diagrams, it's helpful to understand what each line means.

Take this example:

flowchart TD
    Start --> Login
    Login --> Dashboard

Let's break it down.

flowchart

This tells Mermaid that you're creating a flowchart.

Mermaid supports several diagram types, including sequence diagrams, class diagrams, Gantt charts, and entity relationship diagrams. The keyword at the beginning tells Mermaid which type to generate.

TD

TD stands for Top Down.

It controls the direction of the diagram.

In this case, the flow starts at the top and moves downward.

Later in this guide, you'll learn other layout options such as left-to-right and right-to-left.

-->

The arrow connects two nodes.

For example:

Start --> Login

means the process moves from Start to Login.

You can think of it as saying:

"Go from Start to Login."

Node Names

Words like:

Start

Login

Dashboard

are called nodes.

Nodes represent different steps, actions, or objects in your diagram.

Each node becomes a box or shape when Mermaid renders the diagram.

Choosing clear and descriptive names makes your diagrams much easier to understand.

Why Developers Love Mermaid

Mermaid has become popular because it solves several common documentation problems.

Instead of creating diagrams as images, teams can:

  • Edit diagrams using plain text.
  • Review changes in Git.
  • Keep documentation and diagrams together.
  • Reuse diagrams across projects.
  • Update workflows in seconds instead of redesigning images.

This makes Mermaid especially valuable for open-source projects, software documentation, technical blogs, and project documentation.

As documentation grows, text-based diagrams are much easier to maintain than image files.

Flowcharts in Mermaid

If you're new to Mermaid, flowcharts are the best place to start.

A flowchart is a simple way to show how a process works from one step to the next. Instead of describing a workflow with long paragraphs, you can present it visually so readers understand it at a glance.

Flowcharts are commonly used for:

  • Website navigation
  • User login processes
  • Order processing
  • API workflows
  • Business processes
  • Decision making
  • Software documentation

Because they're so flexible, flowcharts are the most widely used Mermaid diagram type.

Creating Your First Flowchart

Every Mermaid flowchart begins with the flowchart keyword, followed by the direction of the diagram.

Example:

```mermaid
flowchart TD
    Start --> Login
    Login --> Dashboard
```

This creates a simple workflow:

Start
  │
  ▼
Login
  │
  ▼
Dashboard

Although the syntax is simple, it can represent almost any process.

Choosing the Diagram Direction

Mermaid lets you control the direction of your flowchart.

This helps you create diagrams that fit your content and screen layout.

Direction Meaning
TD Top to Bottom
BT Bottom to Top
LR Left to Right
RL Right to Left

Top to Bottom

This is the default layout and is commonly used for tutorials and documentation.

```mermaid
flowchart TD
    Start --> Step 1
    Step 1 --> Step 2
    Step 2 --> Finish
```

Best for:

  • Tutorials
  • Instructions
  • Step-by-step guides

Left to Right

If your workflow is wider than it is tall, a left-to-right layout is often easier to read.

```mermaid
flowchart LR
    Home --> Products
    Products --> Checkout
    Checkout --> Success
```

Best for:

  • Website navigation
  • Shopping journeys
  • User flows

Right to Left

This layout is less common but can be useful in certain workflows.

```mermaid
flowchart RL
    Finish --> Review
    Review --> Start
```

Bottom to Top

You can also build diagrams that flow upward.

```mermaid
flowchart BT
    Finish --> Step 2
    Step 2 --> Start
```

Although it's rarely used, Mermaid supports it when needed.

Connecting Nodes

Nodes are connected using arrows.

The simplest arrow is:

A --> B

This means the flow moves from A to B.

You can create longer workflows by connecting additional nodes.

```mermaid
flowchart TD
    Start --> Login
    Login --> Dashboard
    Dashboard --> Profile
    Profile --> Logout
```

This creates a complete user journey through an application.

Giving Nodes Better Names

Instead of short labels like:

A --> B

use meaningful names.

Example:

```mermaid
flowchart TD
    Visitor --> Login
    Login --> Dashboard
    Dashboard --> Reports
```

Clear labels make your diagrams easier to understand, especially in larger projects.

Adding Text to Arrows

Sometimes you want to explain what happens between two steps.

You can place a label on the connecting arrow.

Example:

```mermaid
flowchart TD
    User -->|Signs In| Dashboard
```

This makes the workflow easier to follow because the relationship between the two steps is clearly described.

Arrow labels are useful for:

  • API requests
  • User actions
  • Approval workflows
  • Business processes

Using Different Node Shapes

Not every step in a process should look the same.

Mermaid supports different node shapes to represent different types of actions.

Rectangle

The standard rectangle is the most commonly used shape.

```mermaid
flowchart TD
    Login[Login Page]
```

Use rectangles for general steps in a workflow.

Rounded Rectangle

Rounded corners often represent the beginning or end of a process.

```mermaid
flowchart TD
    Start(Start)
```

These are commonly used for start and finish points.

Circle

A circle can highlight a specific event or state.

```mermaid
flowchart TD
    A((Success))
```

Diamond

Diamonds represent decisions.

```mermaid
flowchart TD
    Decision{Password Correct?}
```

Decision nodes are ideal when a process can follow more than one path.

Building a Login Flow

Let's combine what you've learned into a practical example.

```mermaid
flowchart TD
    Start --> Login
    Login --> Check{Valid Credentials?}
    Check -->|Yes| Dashboard
    Check -->|No| Error
    Error --> Login
```

This diagram represents a common authentication process.

Workflow:

Start
   │
   ▼
Login
   │
   ▼
Valid Credentials?
   ├── Yes → Dashboard
   └── No  → Error → Login

This type of flowchart is frequently used in application documentation and software design.

Building an Online Shopping Flow

Flowcharts are also useful for documenting business processes.

Example:

```mermaid
flowchart LR
    Browse --> Cart
    Cart --> Checkout
    Checkout --> Payment
    Payment --> Confirmation
```

This simple diagram explains the complete customer journey from browsing products to completing a purchase.

Pro Tip

Keep your flowcharts focused on a single process.

Instead of creating one large diagram with dozens of steps, split complex workflows into multiple smaller diagrams.

Smaller flowcharts are easier to read, easier to update, and much more helpful for your readers.

Sequence Diagrams in Mermaid

Flowcharts show the steps in a process, but they don't explain how different systems communicate with each other.

That's where Sequence Diagrams are useful.

A sequence diagram shows how messages move between different users, applications, or services over time.

They're commonly used for:

  • API documentation
  • Login systems
  • Payment processing
  • Client-server communication
  • Microservices
  • Authentication workflows

Creating a Simple Sequence Diagram

Every sequence diagram starts with the sequenceDiagram keyword.

Example:

```mermaid
sequenceDiagram
    User->>Website: Open homepage
    Website-->>User: Display homepage
```

This represents a simple interaction where the user requests a page and the website responds.

API Request Example

One of the most common uses for sequence diagrams is documenting API requests.

```mermaid
sequenceDiagram
    Client->>Server: Send request
    Server->>Database: Fetch data
    Database-->>Server: Return data
    Server-->>Client: JSON response
```

This example clearly shows how data flows through different parts of an application.

Login Authentication Example

```mermaid
sequenceDiagram
    User->>App: Enter username and password
    App->>Server: Verify credentials
    Server-->>App: Authentication successful
    App-->>User: Login complete
```

This type of diagram is useful in software documentation because it explains the communication between each component.

Class Diagrams in Mermaid

Class diagrams describe the structure of an application.

They're widely used in object-oriented programming to show relationships between classes.

Common use cases include:

  • Software architecture
  • Object-oriented design
  • UML documentation
  • Development planning

Simple Class Diagram

```mermaid
classDiagram
    class User
    class Account

    User --> Account
```

This shows that a User is related to an Account.

As projects grow, class diagrams help developers understand how different parts of the application connect.

Entity Relationship Diagrams in Mermaid

Entity Relationship Diagrams, often called ER diagrams, are used to design and document databases.

They show how database tables relate to one another.

Database designers and backend developers frequently use ER diagrams during the planning stage of a project.

Simple ER Diagram

```mermaid
erDiagram
    CUSTOMER ||--o{ ORDER : places
```

This example shows that a customer can place multiple orders.

ER diagrams are commonly used for:

  • SQL databases
  • Database documentation
  • Backend development
  • System design

State Diagrams in Mermaid

State diagrams describe how something changes from one state to another.

They're useful when an object or process can exist in different conditions.

Examples include:

  • User account status
  • Order status
  • Device status
  • Workflow stages

Example

```mermaid
stateDiagram-v2
    [*] --> Pending
    Pending --> Approved
    Approved --> Completed
```

This diagram represents the different states of a process from start to completion.

Gantt Charts in Mermaid

Gantt charts help visualize project schedules.

Instead of showing communication or workflows, they focus on tasks and timelines.

They're commonly used by:

  • Project managers
  • Development teams
  • Product managers
  • Freelancers

Simple Gantt Chart

```mermaid
gantt
    title Project Timeline
    dateFormat YYYY-MM-DD

    section Planning
    Research :2026-06-01, 5d

    section Development
    Coding :2026-06-06, 10d
```

A Gantt chart makes it easy to see how project tasks are scheduled over time.

Pie Charts in Mermaid

Pie charts display data as percentages.

They're useful when comparing parts of a whole.

Example uses include:

  • Survey results
  • Market share
  • Budget allocation
  • Website traffic sources

Example

```mermaid
pie
    title Traffic Sources
    "Organic Search" : 60
    "Direct" : 20
    "Social Media" : 20
```

This chart quickly shows how visitors reach a website.

Git Graphs in Mermaid

Git Graphs help visualize commit history.

They're useful for explaining Git workflows during training or documentation.

Example

```mermaid
gitGraph
    commit
    branch feature
    checkout feature
    commit
    checkout main
    merge feature
```

Git Graphs are especially helpful for open-source projects and developer documentation.

User Journey Diagrams in Mermaid

User Journey diagrams show the experience of a user while interacting with a product or service.

They're commonly used by:

  • UX designers
  • Product managers
  • Business analysts
  • Development teams

Example

```mermaid
journey
    title User Registration
    section Sign Up
      Create Account: 5: User
      Verify Email: 4: User
    section First Login
      Access Dashboard: 5: User
```

These diagrams help teams understand the user's experience and identify areas for improvement.

Which Diagram Should You Use?

Choosing the right diagram makes your documentation easier to understand.

If you want to show... Use this diagram
Step-by-step process Flowchart
Communication between systems Sequence Diagram
Software architecture Class Diagram
Database relationships ER Diagram
Status changes State Diagram
Project schedule Gantt Chart
Percentage comparison Pie Chart
Git workflow Git Graph
Customer experience User Journey

If you're unsure which diagram to choose, start with a Flowchart. It's the most flexible option and works well for most documentation.

Pro Tip

Don't add diagrams just because you can.

A diagram should make information easier to understand.

If a simple paragraph explains something more clearly than a complex diagram, use the paragraph instead.

The best documentation combines clear writing with helpful visuals.

Mermaid Platform Compatibility

One of the biggest advantages of Mermaid is that it works with many popular documentation tools and Markdown editors.

Instead of creating diagrams in external software and exporting them as images, you can keep everything inside your Markdown files.

However, Mermaid only works if the platform supports it.

Before using Mermaid in your documentation, check whether your editor or documentation platform can render Mermaid diagrams.

Where Can You Use Mermaid Diagrams?

The table below shows Mermaid support in some of the most popular platforms.

Platform Mermaid Support Notes
GitHub ✅ Yes Native support in Markdown files.
GitHub README ✅ Yes Diagrams render directly in supported repositories.
Obsidian ✅ Yes Built-in Mermaid support.
Visual Studio Code ✅ Yes Preview works with supported extensions.
GitLab ✅ Yes Native Mermaid support.
Docusaurus ✅ Yes Supported with configuration.
MkDocs ✅ Yes Usually available through themes or plugins.
Hugo ✅ Yes Depends on the project configuration.
Notion ⚠️ Limited Support depends on your workspace features.
Plain Text Editors ❌ No Mermaid code is displayed as plain text.

If you're unsure whether a platform supports Mermaid, create a small test diagram before adding larger ones to your documentation.

Mermaid Diagrams on GitHub

GitHub is one of the most popular places to use Mermaid.

You can include diagrams in documentation files, project guides, and many README files without creating separate image files.

Example:

```mermaid
flowchart TD
    Start --> Build
    Build --> Test
    Test --> Deploy
```

This is especially useful for open-source projects because the diagram stays alongside your source code.

Whenever the workflow changes, you only need to update a few lines of Mermaid code.

See GitHub Markdown for GFM syntax, README examples, and GitHub-specific features.

Mermaid in Obsidian

Obsidian has built-in support for Mermaid diagrams.

This makes it easy to combine notes, documentation, and diagrams in the same vault.

Many people use Mermaid in Obsidian for:

  • Study notes
  • Software architecture
  • Project planning
  • Mind maps
  • Personal knowledge management

Since everything is stored as Markdown files, your notes remain portable and easy to maintain.

See Obsidian Markdown for vaults, internal links, backlinks, graph view, and note organization.

Mermaid in Visual Studio Code

Visual Studio Code is another popular choice for writing Mermaid diagrams.

Developers often write documentation in VS Code because they can edit Markdown and preview Mermaid diagrams without leaving the editor.

This creates a smooth workflow for technical writing.

See VS Code Markdown for preview, shortcuts, extensions, and documentation workflow in Visual Studio Code.

Best Practices

A well-designed diagram is simple, clear, and easy to understand.

Following these best practices will make your documentation more professional.

Keep Diagrams Focused

Each diagram should explain one process or one idea.

Avoid combining multiple workflows into a single diagram.

Smaller diagrams are easier to read and easier to update later.

Use Clear Labels

Instead of using labels like:

A

B

C

Use descriptive names such as:

User

Login Page

Dashboard

Payment Service

Database

Readers should understand each step without needing additional explanation.

Keep the Flow Logical

Arrange your diagrams so that readers can naturally follow the process.

For example:

Start
   │
   ▼
Login
   │
   ▼
Dashboard
   │
   ▼
Logout

A clear direction makes diagrams much easier to understand.

Avoid Large Diagrams

Large diagrams with dozens of nodes can become difficult to read.

Instead of creating one massive flowchart, split your documentation into several smaller diagrams.

This improves readability and makes future updates much easier.

Use Consistent Naming

If you call something User in one diagram, avoid calling it Customer or Client in another unless they represent different things.

Consistent terminology makes documentation easier to follow.

Add Context Around Diagrams

Never place a diagram without explaining it.

Introduce the diagram first, then explain what readers should notice after viewing it.

This small step greatly improves the learning experience.

Common Mistakes

Many Mermaid rendering problems are caused by simple errors.

Here are the most common ones.

Forgetting the Mermaid Code Block

Mermaid syntax must be wrapped inside a Mermaid code block.

Incorrect:

flowchart TD
A --> B

Correct:

```mermaid
flowchart TD
    A --> B
```

Without the mermaid language identifier, most editors will display the code instead of rendering a diagram.

Using the Wrong Diagram Type

Each Mermaid diagram starts with a keyword.

For example:

  • flowchart
  • sequenceDiagram
  • classDiagram
  • erDiagram
  • gantt
  • pie

Using the wrong keyword will prevent Mermaid from generating the expected diagram.

Incorrect Indentation

Although Mermaid is flexible, inconsistent formatting can make diagrams harder to read and debug.

Keeping your code neatly aligned makes it easier to spot mistakes.

Example:

flowchart TD
    Start --> Login
    Login --> Dashboard

Good formatting also helps when working in a team.

Creating Overly Complex Diagrams

More detail isn't always better.

If a diagram requires scrolling in every direction, it's probably too large.

Split complicated workflows into multiple diagrams.

Your readers will thank you.

Assuming Every Website Supports Mermaid

Not every Markdown editor can render Mermaid diagrams.

If your diagram appears as plain text, check whether the platform supports Mermaid before looking for syntax errors.

Troubleshooting Mermaid Diagrams

If your diagram isn't displaying correctly, check these points:

  • Is the code inside a mermaid code block?
  • Did you use the correct diagram keyword?
  • Are all nodes connected properly?
  • Is your Markdown editor compatible with Mermaid?
  • Are there any typing mistakes in node names or arrows?
  • Does your documentation platform support the Mermaid version you're using?

Most rendering issues can be solved by checking these basics.

Pro Tips

Here are a few tips that can make your Mermaid diagrams even better.

Keep Node Names Short

Long labels can make diagrams difficult to read, especially on smaller screens.

Use One Diagram Per Topic

If you're documenting an API, create one diagram for authentication and another for data flow instead of combining everything together.

Update Diagrams with Your Documentation

Whenever your application changes, update the Mermaid diagram at the same time.

Keeping diagrams synchronized with documentation prevents confusion.

Store Diagrams in Version Control

Because Mermaid diagrams are plain text, they work perfectly with Git.

This allows you to review changes, compare versions, and collaborate with your team just like source code.

Practice Mermaid Diagrams

The best way to learn is by creating diagrams yourself.

  1. Open the Markdown Editor and create a new document.
  2. Write a simple flowchart with flowchart TD and three connected nodes.
  3. Add a decision diamond and labeled arrows to create a login flow.
  4. Create a sequence diagram showing a client-server API request.
  5. Preview your work in the editor to confirm each diagram renders correctly.

Review your work against this checklist:

  • Diagrams use mermaid fenced code blocks
  • Flowcharts start with the correct diagram keyword and direction
  • Node names are clear and descriptive
  • Sequence diagrams use ->> and -->> arrows correctly
  • Every diagram renders in live preview

Keep the Markdown Cheat Sheet open for quick syntax lookup.

Summary

Mermaid makes it possible to create professional diagrams using nothing more than plain text.

Instead of relying on external design tools, you can build flowcharts, sequence diagrams, class diagrams, database models, project timelines, and many other diagrams directly inside your Markdown documents.

In this guide, you learned:

  • What Mermaid diagrams are
  • How Mermaid works with Markdown
  • How to create your first flowchart
  • The most popular Mermaid diagram types
  • Where Mermaid is supported
  • Best practices for creating clear diagrams
  • Common mistakes and troubleshooting tips
  • How Mermaid improves technical documentation

Whether you're documenting software, designing databases, explaining APIs, or planning projects, Mermaid provides a fast, flexible, and maintainable way to create diagrams. Because everything is written as plain text, your diagrams are easy to edit, version, and keep in sync with the rest of your documentation.

Learning Mermaid is a valuable skill for developers, technical writers, DevOps engineers, educators, and anyone who wants to create modern, easy-to-maintain documentation.

Continue Learning

Continue learning Markdown with these guides:

Available now

Coming soon

  • Markdown Examples

The best way to learn Mermaid Diagrams is by creating diagrams yourself. Open the Markdown Editor — it renders Mermaid diagrams in live preview — or keep the Markdown Cheat Sheet open for quick syntax lookup.

Frequently Asked Questions

  1. 1

    What are Mermaid diagrams?

    Mermaid diagrams are text-based diagrams that are created using simple syntax inside a Markdown code block. Instead of drawing shapes manually, you write a few lines of Mermaid code, and a supported application renders it as a visual diagram. Mermaid is widely used for software documentation, technical writing, project planning, and system design.

  2. 2

    Do Mermaid diagrams work with Markdown?

    Yes. Mermaid diagrams are commonly written inside Markdown files using a `mermaid` code block. For example: ```mermaid flowchart TD Start --> Finish ``` The diagram will render correctly if your Markdown editor or documentation platform supports Mermaid.

  3. 3

    Does GitHub support Mermaid diagrams?

    Yes. GitHub supports Mermaid diagrams in Markdown, allowing you to include flowcharts, sequence diagrams, class diagrams, and several other diagram types directly in your documentation. This makes it much easier to keep diagrams and source code together in the same repository.

  4. 4

    Does Visual Studio Code support Mermaid?

    Yes. Visual Studio Code can preview Mermaid diagrams with supported extensions and Markdown preview features. Many developers use VS Code to write and preview Mermaid diagrams before publishing documentation.

  5. 5

    Can I use Mermaid in Obsidian?

    Yes. Obsidian includes built-in support for Mermaid diagrams. You can create flowcharts, sequence diagrams, Gantt charts, and many other diagram types directly inside your notes without installing additional software.

  6. 6

    Is Mermaid free to use?

    Yes. Mermaid is an open-source project and is free for personal, educational, and commercial use. This makes it an excellent choice for developers, teams, and organizations that want to create documentation without relying on image-editing software.

  7. 7

    Which Mermaid diagram should I use?

    The best diagram depends on what you're trying to explain. | Goal | Recommended Diagram | | ------------------------- | ------------------- | | Show a process | Flowchart | | Explain API communication | Sequence Diagram | | Design software structure | Class Diagram | | Model a database | ER Diagram | | Track project tasks | Gantt Chart | | Compare percentages | Pie Chart | | Show Git history | Git Graph | | Explain user experience | User Journey | Choosing the right diagram makes your documentation easier to understand.

  8. 8

    Why isn't my Mermaid diagram rendering?

    Some common reasons include: - The platform doesn't support Mermaid. - The code isn't inside a `mermaid` code block. - There's a syntax error. - The diagram type is incorrect. - Your editor doesn't support the Mermaid version you're using. Always preview your document before publishing.

  9. 9

    Can I customize Mermaid diagrams?

    Yes. Mermaid supports many customization options, including different layouts, themes, shapes, styles, colors, and labels. As you become more familiar with Mermaid, you can create diagrams that match the style of your documentation.

  10. 10

    Is Mermaid better than creating image diagrams?

    For documentation, many teams prefer Mermaid because diagrams are stored as text. This means you can edit diagrams quickly, track changes with Git, collaborate with your team, keep diagrams synchronized with documentation, and avoid managing separate image files. For software documentation, this approach is often faster and easier to maintain.