<!--
Sitemap:
- [What is Vocs](/introduction/what-is-vocs): Learn why Vocs exists and when to use it
- [Getting Started](/introduction/getting-started): Install Vocs and create your first documentation site
- [Project Structure](/introduction/project-structure): Overview of the structure of a Vocs project
- [Writing Docs with AI](/introduction/writing-docs-with-ai): Use an AI agent to create and maintain Vocs documentation
- [Markdown Extensions](/writing/markdown-extensions): Features and syntax of Markdown in Vocs
- [Code & Syntax Highlighting](/writing/syntax-highlighting): Rich markup and annotations for code
- [Twoslash](/writing/twoslash): Add type-aware annotations to code examples
- [Code Snippets](/writing/code-snippets): Include and reuse code in Markdown
- [Markdown Snippets](/writing/markdown-snippets): Include other Markdown files in MDX
- [React in Markdown](/writing/react): Compose MDX pages with React components
- [Mermaid Diagrams](/writing/mermaid): Render diagrams from text using Mermaid
- [Assets](/writing/assets): Manage images, fonts, icons, and other docs assets
- [Frontmatter](/writing/frontmatter): Configure page metadata, layouts, search, and UI visibility
- [Navigation](/features/navigation): Keep docs navigation synced with routes
- [Search](/features/search): Built-in client-side search powered by MiniSearch
- [Layouts](/features/layouts): Choose and customize page shells for your docs
- [Slots](/features/slots): Inject custom components into the docs shell
- [Theming](/features/theming): Customize colors, typography, spacing, logos, and code themes
- [Tailwind CSS](/features/tailwind): Use Tailwind utilities in Vocs pages and components
- [Dynamic OG Images](/features/dynamic-og-images): Generate social preview images from page metadata
- [Page Feedback](/features/feedback): Collect page-level feedback from readers
- [Redirects](/features/redirects): Preserve old URLs and route legacy paths to new locations
- [API Routes](/features/api-routes): Add server-rendered endpoints to your docs site
- [Agent Support](/features/agent-support): Serve documentation in machine-readable form for AI agents
- [Ask AI](/features/ask-ai): Built-in AI assistant menu on every page
- [MCP Server](/features/mcp-server): Expose your docs and source code to AI assistants
- [Changelog Generation](/features/changelog-generation): Fetch release notes and render a changelog page
- [Site Configuration](/reference/site-config): Reference for options accepted by defineConfig
- [Frontmatter Reference](/reference/frontmatter): All frontmatter fields accepted by a Vocs MDX page
- [Components](/reference/components): Reference for the public React components exported from Vocs
- [Hooks](/reference/hooks): Reference for the React hooks exported from Vocs
- [Changelog](/changelog): Release history for Vocs
-->

# Mermaid Diagrams \[Render diagrams from text using Mermaid]

Vocs renders [Mermaid](https://mermaid.js.org/) diagrams from fenced code blocks. Tag a code block with the `mermaid` language and Vocs streams the diagram into the page on the client.

## Usage

Write Mermaid syntax inside a `mermaid` code block:

````mdx
```mermaid
graph LR
  A[Client] --> B[Vite]
  B --> C[Waku]
  C --> D[MDX]
  D --> E[HTML]
```
````

The block renders as an SVG diagram with built-in light/dark theming, loading states, and error fallbacks:

```mermaid
graph LR
  A[Client] --> B[Vite]
  B --> C[Waku]
  C --> D[MDX]
  D --> E[HTML]
```

## Supported Diagrams

Vocs supports the full Mermaid syntax, including:

* **Flowcharts** (`graph`, `flowchart`)
* **Sequence diagrams**
* **Class diagrams**
* **State diagrams**
* **Entity-relationship diagrams**
* **Gantt charts**
* **Pie charts**
* **Git graphs**
* **Mindmaps**
* **Timeline**
* **Quadrant charts**
* **C4 diagrams**

See the [Mermaid documentation](https://mermaid.js.org/intro/) for full syntax reference.

## Examples

### Sequence Diagram

:::code-group

<div data-title="Preview">
  ```mermaid
  sequenceDiagram
    participant U as User
    participant A as Agent
    participant V as Vocs

    U->>A: Read the docs for X
    A->>V: GET /llms.txt
    V-->>A: Page index
    A->>V: GET /features/x.md
    V-->>A: Raw markdown
    A-->>U: Answer with citations
  ```
</div>

```text [Code]
sequenceDiagram
  participant U as User
  participant A as Agent
  participant V as Vocs

  U->>A: Read the docs for X
  A->>V: GET /llms.txt
  V-->>A: Page index
  A->>V: GET /features/x.md
  V-->>A: Raw markdown
  A-->>U: Answer with citations
```

:::

### State Diagram

:::code-group

<div data-title="Preview">
  ```mermaid
  stateDiagram-v2
    [*] --> Draft
    Draft --> Review: submit
    Review --> Published: approve
    Review --> Draft: request changes
    Published --> [*]
  ```
</div>

```text [Code]
stateDiagram-v2
  [*] --> Draft
  Draft --> Review: submit
  Review --> Published: approve
  Review --> Draft: request changes
  Published --> [*]
```

:::

### Class Diagram

:::code-group

<div data-title="Preview">
  ```mermaid
  classDiagram
    class Config {
      +string title
      +Sidebar[] sidebar
      +TopNav[] topNav
    }
    class Sidebar {
      +string text
      +string link
    }
    Config --> Sidebar
  ```
</div>

```text [Code]
classDiagram
  class Config {
    +string title
    +Sidebar[] sidebar
    +TopNav[] topNav
  }
  class Sidebar {
    +string text
    +string link
  }
  Config --> Sidebar
```

:::

## Theming

Mermaid diagrams inherit Vocs's light/dark color scheme automatically. Customize the diagram appearance through the [Mermaid theme variables](https://mermaid.js.org/config/theming.html) by adding `%%{init}%%` directives at the top of a diagram, or globally via your `_root.css`.

## How It Works

The remark pipeline converts `mermaid` code blocks into a `<div data-v-mermaid-chart="...">` element. A small client-side component loads `mermaid` lazily and renders the SVG into the placeholder. The Mermaid runtime is only bundled on pages that actually use a diagram.

## See Also

* [Markdown Extensions](/writing/markdown-extensions)
* [Code & Syntax Highlighting](/writing/syntax-highlighting) — for regular code blocks
