Mermaid Diagrams Demo

A comprehensive guide to using Mermaid.js diagrams in your blog posts - flowcharts, sequence diagrams, class diagrams, and more.

published: reading time: 6 min read author: Geek Workbench updated: May 17, 2026
Quick Summary

This demo shows flowchart, sequence, class, ER, and state diagrams in Markdown. Each rendered example has a text summary and an expandable source block, with accessible diagram titles and descriptions. It also explains the site's Mermaid version setup and links to the content authoring guide.

Mermaid turns text into diagrams. This page shows five common diagram types and keeps a plain-language summary and the source for each example near its rendered form.

What is Mermaid.js?

Mermaid is a JavaScript diagram renderer with a text-based syntax. This site loads mermaid@11 from jsDelivr, which pins the major version but can move to a later 11.x release. The repository’s lockfile pins the local Mermaid package to 11.13.0, but that does not pin the browser’s CDN copy. These examples use basic Mermaid 11 syntax; check the rendered page after Mermaid updates, especially when using newer features.

Flowchart

Use a flowchart to show a process with branches, such as a decision tree or user journey.

graph TD
    accTitle: Example deployment decision flow
    accDescr: Start at the top, check whether the system works, and either deploy and monitor or debug before checking again.
    A[Start] --> B{Is it working?}
    B -->|Yes| C[Great!]
    B -->|No| D[Debug]
    D --> E[Check logs]
    E --> F[Fix issue]
    F --> B
    C --> G[Deploy to production]
    G --> H[Monitor]
    H -->|Issues| D
    H -->|Stable| I[Done]

Text summary: the process loops through debugging until it works, then deploys and monitors; a monitoring issue sends it back to debugging.

View the Mermaid source
graph TD
    accTitle: Example deployment decision flow
    accDescr: Start at the top, check whether the system works, and either deploy and monitor or debug before checking again.
    A[Start] --> B{Is it working?}
    B -->|Yes| C[Great!]
    B -->|No| D[Debug]
    D --> E[Check logs]
    E --> F[Fix issue]
    F --> B
    C --> G[Deploy to production]
    G --> H[Monitor]
    H -->|Issues| D
    H -->|Stable| I[Done]

Sequence Diagram

Use a sequence diagram to show which actors call each other and in what order.

sequenceDiagram
    accTitle: Form submission sequence
    accDescr: The user submits a form; the browser sends it to the server, which stores it in the database and returns a success response.
    participant User
    participant Browser
    participant Server
    participant Database

    User->>Browser: Submit form
    Browser->>Server: POST /api/submit
    Server->>Database: Save data
    Database-->>Server: Confirmation
    Server-->>Browser: 200 OK
    Browser-->>User: Success message

Text summary: the user submits a form in the browser, the server stores it, then the success response travels back to the user.

View the Mermaid source
sequenceDiagram
    accTitle: Form submission sequence
    accDescr: The user submits a form; the browser sends it to the server, which stores it in the database and returns a success response.
    participant User
    participant Browser
    participant Server
    participant Database

    User->>Browser: Submit form
    Browser->>Server: POST /api/submit
    Server->>Database: Save data
    Database-->>Server: Confirmation
    Server-->>Browser: 200 OK
    Browser-->>User: Success message

Class Diagram

Class diagrams show classes, their fields and methods, and the relationships between them.

classDiagram
    accTitle: Animal class inheritance
    accDescr: Dog and Cat inherit from Animal. Each class has its own fields and operations.
    class Animal {
        +String name
        +int age
        +makeSound()
        +move()
    }
    class Dog {
        +String breed
        +bark()
        +fetch()
    }
    class Cat {
        +String color
        +meow()
        +purr()
    }
    Animal <|-- Dog
    Animal <|-- Cat

Text summary: Dog and Cat specialize Animal; each subclass adds its own field and methods.

View the Mermaid source
classDiagram
    accTitle: Animal class inheritance
    accDescr: Dog and Cat inherit from Animal. Each class has its own fields and operations.
    class Animal {
        +String name
        +int age
        +makeSound()
        +move()
    }
    class Dog {
        +String breed
        +bark()
        +fetch()
    }
    class Cat {
        +String color
        +meow()
        +purr()
    }
    Animal <|-- Dog
    Animal <|-- Cat

Entity Relationship Diagram

Use an ER diagram to map database entities and their relationships, such as users, orders, and products.

erDiagram
    accTitle: User, order, product, and review relationships
    accDescr: A user places orders and writes reviews. Orders contain products, and products have reviews.
    USER ||--o{ ORDER : places
    ORDER ||--o{ PRODUCT : contains
    USER ||--o{ REVIEW : writes
    PRODUCT ||--o{ REVIEW : has

    USER {
        string id
        string email
        string name
        date created_at
    }
    ORDER {
        int id
        date order_date
        string status
    }
    PRODUCT {
        int id
        string name
        decimal price
    }
    REVIEW {
        int id
        int rating
        string comment
    }

Text summary: one user can place many orders and write many reviews; an order can contain multiple products, and a product can have reviews.

View the Mermaid source
erDiagram
    accTitle: User, order, product, and review relationships
    accDescr: A user places orders and writes reviews. Orders contain products, and products have reviews.
    USER ||--o{ ORDER : places
    ORDER ||--o{ PRODUCT : contains
    USER ||--o{ REVIEW : writes
    PRODUCT ||--o{ REVIEW : has

    USER {
        string id
        string email
        string name
        date created_at
    }
    ORDER {
        int id
        date order_date
        string status
    }
    PRODUCT {
        int id
        string name
        decimal price
    }
    REVIEW {
        int id
        int rating
        string comment
    }

State Diagram

State diagrams help you track all the possible states something can be in, and what transitions exist between those states.

stateDiagram-v2
    accTitle: Publishing workflow states
    accDescr: A draft can be submitted for review, returned for changes, approved, and published. A published item can be unpublished back to draft.
    [*] --> Draft
    Draft --> Review: Submit
    Review --> Approved: Reviewer OK
    Review --> Draft: Needs changes
    Approved --> Published: Publish
    Published --> [*]
    Published --> Draft: Unpublish

Text summary: a draft moves through review before publication; reviewers can send it back, and a published item can return to draft.

View the Mermaid source
stateDiagram-v2
    accTitle: Publishing workflow states
    accDescr: A draft can be submitted for review, returned for changes, approved, and published. A published item can be unpublished back to draft.
    [*] --> Draft
    Draft --> Review: Submit
    Review --> Approved: Reviewer OK
    Review --> Draft: Needs changes
    Approved --> Published: Publish
    Published --> [*]
    Published --> Draft: Unpublish

How to Use

In a post, wrap Mermaid syntax in a fenced code block labeled mermaid:

```mermaid
graph TD
    accTitle: Simple two-step flow
    accDescr: Start connects directly to End.
    A[Start] --> B[End]
```

Text summary: the diagram has one step, from Start to End.

The site replaces Mermaid code blocks with rendered diagrams when the page loads. Rendering depends on the browser loading the CDN module. Keep the source visible in Markdown for editing and troubleshooting, and include a text summary so readers can understand the relationships if the SVG does not render or is difficult to inspect.

For diagrams that carry information, add an accTitle and accDescr in the source. Mermaid uses these to expose an accessible SVG title and description; they complement rather than replace the visible text summary. See Mermaid’s accessibility documentation. The examples here use basic flowchart, sequence, class, ER, and state syntax; confirm newer syntax against the renderer version your site actually deploys.

For a design-focused example, see Class Diagrams for Design Conversations. To add a post to this site, follow the repository’s Adding Content guide.

Conclusion

Mermaid diagrams live in Markdown as text, so you can edit them alongside the explanation. Keep the source and a short text summary available when a diagram carries information readers need.

Category

Related Posts

Capstone: Build a Typed React Task Tracker

Build a React task tracker with typed filters, accessible forms, versioned local storage, migration recovery, and a behavior test.

#react #typescript #tutorial

Daily Git Workflow: From Morning Pull to Evening Push

Hands-on tutorial for a productive daily Git workflow from morning pull to evening push, covering branching, committing, reviewing, and pushing best practices.

#git #workflow #daily

Initializing Git Repositories: git init, Clone, and Bare Repositories

Tutorial on git init, cloning remote repositories, bare repositories, and understanding repository structure for new and existing projects.

#git #init #clone