> ## Documentation Index
> Fetch the complete documentation index at: https://docs.autype.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Diagrams

> Render diagrams from text using Mermaid, PlantUML, GraphViz, and 15+ other diagram languages.

Autype renders diagrams directly from text-based diagram languages. Write your diagram code in a fenced code block with the diagram language as the language identifier — it will be automatically rendered as an image in the exported document.

<Note>
  Diagrams are only rendered as images when **Render as Image** is enabled. You can control this globally via the [Styles panel → Code Blocks](/getting-started/editor/sidebar-styles#code-blocks) setting, or override it per block with the `renderAsImage` attribute directly on the code block.
</Note>

## Basic syntax

Use a fenced code block with a supported diagram language:

````markdown theme={null}
```mermaid
graph TD
    A[Start] --> B{Decision?}
    B -->|Yes| C[Action 1]
    B -->|No| D[Action 2]
    C --> E[End]
    D --> E
```
````

The diagram is automatically rendered as a PNG image in the exported PDF/DOCX document.

## Supported diagram languages

| Language                                                         | Code identifier     | Description                                                           |
| ---------------------------------------------------------------- | ------------------- | --------------------------------------------------------------------- |
| [Mermaid](https://github.com/knsv/mermaid)                       | `mermaid`           | Flowcharts, sequence diagrams, class diagrams, Gantt charts, and more |
| [PlantUML](https://github.com/plantuml/plantuml)                 | `plantuml`          | UML diagrams (class, sequence, activity, use case, etc.)              |
| [GraphViz](https://www.graphviz.org/)                            | `graphviz` or `dot` | Graph and network visualizations                                      |
| [Structurizr](https://github.com/structurizr/dsl)                | `structurizr`       | C4 architecture diagrams                                              |
| [BlockDiag](https://github.com/blockdiag/blockdiag)              | `blockdiag`         | Simple block diagrams                                                 |
| [SeqDiag](https://github.com/blockdiag/seqdiag)                  | `seqdiag`           | Sequence diagrams                                                     |
| [ActDiag](https://github.com/blockdiag/actdiag)                  | `actdiag`           | Activity diagrams with swimlanes                                      |
| [NwDiag](https://github.com/blockdiag/nwdiag)                    | `nwdiag`            | Network topology diagrams                                             |
| [PacketDiag](https://github.com/blockdiag/nwdiag)                | `packetdiag`        | Packet/protocol header diagrams                                       |
| [C4 with PlantUML](https://github.com/RicardoNiepel/C4-PlantUML) | `c4plantuml`        | C4 architecture model using PlantUML syntax                           |
| [DBML](https://github.com/softwaretechnik-berlin/dbml-renderer)  | `dbml`              | Database markup language for ER diagrams                              |
| [Ditaa](https://ditaa.sourceforge.net)                           | `ditaa`             | ASCII art to diagram conversion                                       |
| [ERD](https://github.com/BurntSushi/erd)                         | `erd`               | Entity-relationship diagrams                                          |
| [TikZ](https://github.com/pgf-tikz/pgf)                          | `tikz`              | LaTeX-based technical drawings                                        |
| [UMlet](https://github.com/umlet/umlet)                          | `umlet`             | UML diagrams                                                          |
| [Vega](https://github.com/vega/vega)                             | `vega`              | Declarative data visualizations                                       |
| [WireViz](https://github.com/formatc1702/WireViz)                | `wireviz`           | Wiring harness and cable documentation                                |

## Mermaid examples

### Flowchart

````markdown theme={null}
```mermaid
graph TD
    A[Start] --> B{Decision?}
    B -->|Yes| C[Action 1]
    B -->|No| D[Action 2]
    C --> E[End]
    D --> E
```
````

### Sequence diagram

````markdown theme={null}
```mermaid
sequenceDiagram
    participant Client
    participant API
    participant DB

    Client->>API: POST /render
    API->>DB: Save job
    DB-->>API: Job ID
    API-->>Client: 202 Accepted
```
````

### Class diagram

````markdown theme={null}
```mermaid
classDiagram
    class Document {
        +String title
        +Section[] sections
        +render() PDF
    }
    class Section {
        +String type
        +Element[] content
    }
    Document "1" --> "*" Section
```
````

## PlantUML example

````markdown theme={null}
```plantuml
@startuml
start
:Create document;
:Write content;
if (Has variables?) then (yes)
  :Substitute variables;
else (no)
endif
:Render DOCX;
:Convert to PDF;
stop
@enduml
```
````

## GraphViz example

````markdown theme={null}
```graphviz
digraph G {
    rankdir=LR;
    node [shape=box, style=filled, fillcolor="#e8f4fd"];
    Frontend -> API;
    API -> Database;
    API -> Redis;
    Worker -> Redis;
    Worker -> S3;
}
```
````

***

## Captions and anchors

Add `caption` and `anchor` attributes to include the diagram in the [List of Figures](/markup-reference/indices#list-of-figures) and enable [cross-references](/markup-reference/references):

````markdown theme={null}
```mermaid{caption="System Architecture" anchor="fig-architecture"}
graph LR
    A[Client] --> B[API]
    B --> C[Database]
    B --> D[Cache]
```
````

This renders with: *Figure 1: System Architecture*

Reference it elsewhere:

```markdown theme={null}
As shown in [Figure {num}](#fig-architecture), the system uses a layered design.
```

## Alignment

Control horizontal alignment with the `align` attribute:

````markdown theme={null}
```mermaid{align="center" caption="Centered Diagram" anchor="fig-centered"}
graph LR
    A --> B --> C
```
````

***

## Rendering as code (renderAsImage=false)

By default, diagram language code blocks are rendered as images. Set `renderAsImage=false` to display the source code as a regular code block instead:

````markdown theme={null}
```mermaid{renderAsImage=false}
graph TD
    A --> B
    B --> C
```
````

This is useful when you want to show the diagram source code to the reader rather than the rendered diagram.

<Info>
  When `renderAsImage=false` is set on a diagram code block, the block is treated as a regular code block. If it has a `caption`, it appears in the [List of Code Listings](/markup-reference/indices#list-of-code-listings) instead of the List of Figures.
</Info>

### Global default

You can set the default for all code blocks in your document's style settings:

* **defaults → styles → code → renderAsImage**: `true` (default) or `false`

The element-level `renderAsImage` attribute always overrides the global default.

***

## Attribute reference

| Attribute       | Values                    | Description                                                                 |
| --------------- | ------------------------- | --------------------------------------------------------------------------- |
| `renderAsImage` | `true`, `false`           | Render as image (default: `true` for diagram languages) or show source code |
| `caption`       | String                    | Figure caption for auto-numbering in the List of Figures                    |
| `anchor`        | String                    | Anchor ID for cross-references                                              |
| `align`         | `left`, `center`, `right` | Horizontal alignment                                                        |
| `width`         | Number (pixels)           | Width of the rendered diagram image                                         |
| `spacingBefore` | Number (pt)               | Spacing before the diagram                                                  |
| `spacingAfter`  | Number (pt)               | Spacing after the diagram                                                   |

<Note>
  Diagrams are rendered server-side during document export. In the live editor preview, diagram code blocks are displayed as syntax-highlighted code.
</Note>
