article

Mermaid Diagrams in Markdown: Text-Based Visualization for Developers

6 min read

You’ve been there. Someone asks you to document a system architecture, a deployment pipeline, or an API flow. You fire up a drawing tool, spend 45 minutes dragging boxes around, export a PNG, and drop it into your repo. Two weeks later the architecture changes, and that PNG is already wrong. Nobody updates it. Nobody ever updates it.

Mermaid fixes this by letting you write diagrams as text, right inside your Markdown files. The diagram lives next to your code, gets versioned with Git, and renders automatically on platforms like GitHub, GitLab, and Obsidian. No image exports. No separate tools. Just text that turns into visuals.

What Mermaid actually is

Mermaid is a JavaScript library that takes a text-based description and renders it as an SVG diagram. You write something like this inside a fenced code block:

```mermaid
flowchart LR
    A[User] --> B[Server]
    B --> C[(Database)]
```

And it turns into a clean left-to-right flowchart with three connected nodes. The syntax is compact, readable, and version-controllable.

Mermaid supports several diagram types out of the box:

This article series focuses on the three most practical types for day-to-day engineering work: flowcharts, sequence diagrams, and Gantt charts.

Where you can use it

One of the best things about Mermaid is how widely supported it is. You don’t need to install anything special in most cases.

PlatformSupport
GitHub (README, Issues, PRs)Built-in rendering
GitLabBuilt-in rendering
ObsidianNative support
NotionVia code blocks
VS Code / CursorExtension: “Markdown Preview Mermaid Support”
DocusaurusBuilt-in
ConfluenceVia plugin
Jupyter NotebooksVia extension

You can also use the Mermaid Live Editor to prototype diagrams in your browser and export them as SVG or PNG.

Syntax fundamentals

Before jumping into specific diagram types, there are a few universal rules worth knowing.

Node IDs must not contain spaces. Use camelCase or PascalCase:

UserService --> DatabaseHandler

Labels with special characters go in double quotes:

A["Process #1 (main)"] --> B["Step: validation"]

Avoid reserved words as node IDs. Words like end, subgraph, graph, and flowchart will break your diagram. Use something like processEnd or endNode instead.

Don’t hardcode colors. If you add style directives with explicit hex colors, your diagram will look fine in light mode and terrible in dark mode (or vice versa). Let the renderer’s theme handle it.

Themes are available if you want a different look. Add this at the top of your diagram:

%%{init: {'theme': 'forest'}}%%

Available themes: default, forest, dark, neutral, base.

Comments use %% and won’t render:

%% This note is only visible in the source code

A taste of each diagram type

Here’s a quick preview of each type so you know what to expect in the rest of this series.

Flowcharts

Flowcharts describe processes and decision trees. They’re the most versatile diagram type in Mermaid.

```mermaid
flowchart TD
    Start([Start]) --> Input[Get user input]
    Input --> Check{Valid?}
    Check -->|Yes| Process[Process data]
    Check -->|No| Error[Show error]
    Process --> Done([End])
    Error --> Input
```

Key shapes: rectangles [text] for actions, diamonds {text} for decisions, rounded ([text]) for start/end points.

Directions: TD (top-down), LR (left-right), BT (bottom-up), RL (right-left).

Arrow types: --> solid arrow, -.-> dashed, ==> thick, -->|label| with text.

Sequence diagrams

Sequence diagrams show how different actors or services communicate over time. They’re perfect for documenting API interactions, login flows, or microservice choreography.

```mermaid
sequenceDiagram
    participant User
    participant API
    participant DB

    User->>API: GET /api/products
    API->>DB: SELECT * FROM products
    DB-->>API: Result set
    API-->>User: 200 OK (JSON)
```

Solid arrows (->>) represent requests. Dashed arrows (-->>) represent responses. Participants appear in the order you declare them.

Gantt charts

Gantt charts show tasks across a timeline with durations and dependencies. Useful for sprint planning, project roadmaps, and release tracking.

```mermaid
gantt
    title Landing Page Redesign
    dateFormat YYYY-MM-DD

    section Design
    Competitor analysis    :a1, 2026-03-10, 3d
    Create mockups         :a2, after a1, 5d
    Design approval        :a3, after a2, 2d

    section Development
    Frontend build         :a4, after a3, 7d
    Testing                :a5, after a4, 3d

    section Launch
    Deploy                 :a6, after a5, 1d
```

Tasks can depend on each other using after taskId. Sections group related work visually.

Why text-based diagrams matter

If you’ve worked on a team where architecture docs go stale within a sprint, you already get why this matters. But here are the specific wins:

The tradeoff is that you give up pixel-level control over positioning. Mermaid decides where nodes go, and sometimes the layout isn’t perfect. For most engineering documentation, that’s an acceptable exchange.

What’s next

This is part 1 of a three-part series. The next two articles go deeper:

If you want to experiment right now, try the interactive playground below or open the Mermaid Live Editor.

Interactive playground

Edit the code and switch between tabs to see the result. Pick any diagram type to get started.

Try it:

TL;DR

What Mermaid does:

Three main diagram types:

Why it matters: