Diagrams

Overview

Quarto has native support for embedding Mermaid and Graphviz diagrams. This enables you to create flowcharts, sequence diagrams, state diagrams, gantt charts, and more using a plain text syntax inspired by markdown.

For example, here we embed a flowchart created using Mermaid:

```{mermaid}
flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]
```

flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]

As illustrated above, Mermaid diagrams are embedded using {mermaid} executable cells. Graphviz diagrams are embedded using {dot} executable cells. Note that cell options are added with slightly different syntax: %%| for {mermaid}, and //| for {dot}.

Note

For print output formats like pdf or docx, diagram rendering makes use of the Chrome or Edge web browser to create a high-quality PNG. Quarto can automatically use an existing version of Chrome or Edge on your system, or alternatively if you don’t have either installed, you can install a lighter-weight version called Chrome Headless Shell (see Chrome Install below for details).

Mermaid

Mermaid is a Javascript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams.

Mermaid diagrams use %% as their comment syntax, and so cell options are declared using %%|. Cell options must be included directly beneath the start of the diagram code chunk.

Above we demonstrated a flowchart created with Mermaid, here is a sequence diagram (also embedded using a {mermaid} executable cell):

```{mermaid}
sequenceDiagram
  participant Alice
  participant Bob
  Alice->>John: Hello John, how are you?
  loop Healthcheck
    John->>John: Fight against hypochondria
  end
  Note right of John: Rational thoughts <br/>prevail!
  John-->>Alice: Great!
  John->>Bob: How about you?
  Bob-->>John: Jolly good!
```

sequenceDiagram
  participant Alice
  participant Bob
  Alice->>John: Hello John, how are you?
  loop Healthcheck
    John->>John: Fight against hypochondria
  end
  Note right of John: Rational thoughts <br/>prevail!
  John-->>Alice: Great!
  John->>Bob: How about you?
  Bob-->>John: Jolly good!

Note that Mermaid output varies depending on the target format (e.g. HTML vs. print-based). See the section below on Mermaid Formats for additional details.

To learn more about using Mermaid, see the Mermaid website or the Mermaid book (which is written by the creator of Mermaid).

Graphviz

The Graphviz layout programs take descriptions of graphs in a simple text language, and make diagrams in useful formats. Graphviz has many useful features for concrete diagrams, such as options for colors, fonts, tabular node layouts, line styles, hyperlinks, and custom shapes.

Graphviz diagrams use // as their comment syntax, and so cell options are declared using //|. Cell options must be included directly beneath the start of the diagram code chunk.

For example, here is a simple undirected graph created using graphviz:

```{dot}
graph G {
  layout=neato
  run -- intr;
  intr -- runbl;
  runbl -- run;
  run -- kernel;
  kernel -- zombie;
  kernel -- sleep;
  kernel -- runmem;
  sleep -- swap;
  swap -- runswap;
  runswap -- new;
  runswap -- runmem;
  new -- runmem;
  sleep -- runmem;
}
```

⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini run ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini intr ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini kernel ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini runbl ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini zombie ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini sleep ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini runmem ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini swap ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini runswap ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini new ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini

To learn more about Graphviz, see the Graphviz website, this list of simple Graphiz Examples, or the Graphviz Gallery.

Authoring

There are a variety of tools available to improve your productivity authoring diagrams:

  1. The Mermaid Live Editor is an online tool for editing and previewing Mermaid diagrams in real time.

  2. Graphviz Online provides a similar tool for editing Graphviz diagrams.

  3. RStudio includes support for editing and previewing .mmd and .dot files (with help from the DiagrammeR package).

  4. The Quarto Extension for VS Code and Positron (available on both OpenVSX and Microsoft’s marketplace) supports live preview of diagrams embedded in .qmd files and in .mmd and .dot files:

    A Quarto document being edited in Visual Studio Code, with a live preview of the currenly edited diagram shown in a pane to the right

Cross-References

Diagrams can be treated as figures the same way that images and plot output are. For example, if we added the following figure options to the diagram above:

```{dot}
//| label: fig-simple
//| fig-cap: "This is a simple graphviz graph."
```

We’d get this output:

⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini run ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini intr ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini kernel ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini runbl ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini zombie ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini sleep ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini runmem ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini swap ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini runswap ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini new ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini
Figure 1: This is a simple graphviz graph.

We could then create a cross-reference to the diagram with:

@fig-simple

To create a cross-references to a diagram using div syntax, treat it like a figure. For example, Figure 2 is created using:

::: {#fig-simple}

```{dot}
graph {
  A -- B
}
```

This is a simple graphviz graph
:::

⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini A ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini B ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini

Figure 2: This is a simple graphviz graph

If you would rather give diagrams a label and counter distinct from figures, consider defining Custom Cross-Reference Types.

File Include

You might find it more convenient to edit your diagram in a standalone .dot or .mmd file and then reference it from within your .qmd document. You can do this by adding the file option to a Mermaid or Graphviz cell.

For example, here we include a very complex diagram whose definition would be too unwieldy to provide inline:

```{dot}
//| label: fig-linux-kernel
//| fig-cap: "A diagram of the Linux kernel."
//| file: linux-kernel-diagram.dot
```
⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini System calls ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini system ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini processing ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini proc & sysfs file systems ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini Device Model ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini system run, modules, generic HW access ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini bus drivers ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini buses: PCI, USB ... ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini Sockets ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini networking ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini protocol families ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini protocols: TCP, UDP, IP ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini network interfaces and drivers ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini network: Ethernet, WiFi ... ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini NFS ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini Processes ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini memory ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini Tasks ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini synchronization ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini Scheduler ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini interrupts core, CPU arch ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini CPU ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini © 2007-2022 Costa Shulyupin http://www.MakeLinux.net/kernel/diagram ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini memory access ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini Virtual memory ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini memory mapping ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini logical memory ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini Swap ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini Page Allocator ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini MMU, RAM ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini Block devices and drivers ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini storage devices: SCSI, NVMe ... ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini page cache ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini storage ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini files and directories ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini Virtual File System ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini logical filesystems: ext3, xfs ... ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini char devices ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini human interface ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini input subsystem ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini HI class drivers ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini HI peripherals drivers ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini keyboard, mouse, display, audio ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini functions ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini layers ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini user space interfaces ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini virtual subsystems ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini bridges ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini logical ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini hardware interfaces ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini electronics, hardware ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini ⚡ Match Highlights: docs/authoring/diagrams.html - Pertandingan Hari Ini Linux kernel diagram
Figure 3: A diagram of the Linux kernel.

Note that the label and fig-cap attributes still work as expected with file includes.

Sizing

By default, diagrams are rendered at their natural size (i.e. they are not stretched to fit the default figure size for the current document). Within HTML output formats, diagrams are also made responsive, so that their width doesn’t overflow the current page column. This is similar to the treatment given to images and dynamic JavaScript widgets.

You can disable responsive sizing by specifying the fig-responsive: false option. You can also specify explicit sizes via fig-width and fig-height. For example, here we want to make a mermaid diagram a bit bigger because it contains only a few elements:

```{mermaid}
%%| fig-width: 6.5
flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
```

flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}

Mermaid Formats

When you include a Mermaid diagram in a document, the diagram format used is chosen automatically based on the output format:

Format Output
HTML (html, revealjs, etc.) Mermaid native (JavaScript)
GitHub Flavored Markdown (gfm) Mermaid code block
Other Formats (pdf, docx, etc.) PNG image

The Mermaid native format is used by default whenever the underlying output format supports JavaScript.

When using format: gfm, diagrams will be emitted as plain mermaid code blocks. This is because both GitHub and GitLab natively support rendering Mermaid diagrams from code.

For formats that don’t do special handling of Mermaid or lack a JavaScript run-time (e.g. formats like pdf, docx, epub, etc.) a PNG image is created using Chrome.

You can change the default behavior using the mermaid-format option. For example:

---
format:
  gfm:
    mermaid-format: png
---

Valid values for mermaid-format include js, png, and svg,

WarningSVG Format Limitations with PDF Output through LaTeX

When rendering to LaTeX-based formats, mermaid-format: svg requires additional tooling and may have rendering issues:

  • Requires installation: rsvg-convert or inkscape must be available in your system PATH for Quarto to convert SVG to PDF to include in LaTeX.
  • Potential rendering issues: Text clipping in diagrams with multi-line labels
  • Recommended: Keep default mermaid-format: png for PDF output with LaTeX.

For more details, including installation instructions and Inkscape configuration, see SVG Images.

Mermaid Themes

The following sections describe the ways in which you can control the color theme of Mermaid diagrams:

  • Using the current document theme.
  • Using one of Mermaid’s own color themes via a YAML option.
  • Using SCSS and CSS variables.

Default Colors for Mermaid Diagrams

If you use Quarto’s bootswatch built-in themes, including the default theme, or a custom theme that uses the same SCSS variables, your Mermaid diagrams will automatically follow your theme.

The following examples demonstrate this with a few of Quarto’s built-in bootswatch themes.

You can read more about the correspondence between Bootstrap’s SCSS variables and Quarto’s Mermaid SCSS variables, and how to change it, below in Customizing the Mermaid Theme.

Using Mermaid’s Built-in Themes

If you want to use Mermaid’s own themes, you can do so by configuring the mermaid option in your YAML front matter:

format:
  html:
    mermaid:
      theme: forest

The available themes from mermaid are: default, dark, forest, and neutral.

Customizing the Mermaid Theme

Quarto provides its own Mermaid SCSS and CSS variables that can be overwritten to allow some customization of the diagram theme. The SCSS variables, together with their default values, are:

$mermaid-bg-color: $body-bg;
$mermaid-edge-color: $secondary;
$mermaid-node-fg-color: $body-color;
$mermaid-fg-color: $body-color;
$mermaid-fg-color--lighter: lighten($body-color, 10%);
$mermaid-fg-color--lightest: lighten($body-color, 20%);
$mermaid-font-family: $font-family-sans-serif;
$mermaid-label-bg-color: $body-bg;
$mermaid-label-fg-color: $primary;
$mermaid-node-bg-color: rgba($primary, 0.1);
$mermaid-node-fg-color: $primary;

Their CSS variable counterparts are:

:root {
  --mermaid-bg-color: #{$mermaid-bg-color};
  --mermaid-edge-color: #{$mermaid-edge-color};
  --mermaid-node-fg-color: #{$mermaid-node-fg-color};
  --mermaid-fg-color: #{$mermaid-fg-color};
  --mermaid-fg-color--lighter: #{$mermaid-fg-color--lighter};
  --mermaid-fg-color--lightest: #{$mermaid-fg-color--lightest};
  --mermaid-font-family: #{$mermaid-font-family};
  --mermaid-label-bg-color: #{$mermaid-label-bg-color};
  --mermaid-label-fg-color: #{$mermaid-label-fg-color};
  --mermaid-node-bg-color: #{$mermaid-node-bg-color};
  --mermaid-node-fg-color: #{$mermaid-node-fg-color};
}

For example, to provide a custom color for the background of the nodes you could add a custom CSS stylesheet containing:

:root {
  --mermaid-node-bg-color: #375a7f;
}

You can find the correspondence between Quarto’s variables and Mermaid’s native CSS classes in Quarto’s source code in the file embed-mermaid.css.

Code Echo

Note that unlike other executable cell handlers (e.g. {python}), cells with diagrams don’t display their code in the rendered document by default. You can display code by adding an echo: true option in a comment at the top the cell.

To include code for {mermaid}, add %%| echo: true to the top of the cell. For example:

```{mermaid}
%%| echo: true
```

To include code for {dot}, add //| echo: true to the top of the cell. For example:

```{dot}
//| echo: true
```

Chrome Install

For printing to output formats like pdf or docx, diagram rendering makes use of the Chrome or Edge web browser to create a high-quality PNG.

Quarto can automatically use an existing version of Chrome or Edge on your system for rendering. Alternatively, if you don’t have either installed, you can install Chrome Headless Shell for use by Quarto:

Terminal
quarto install chrome-headless-shell

Chrome Headless Shell is a lightweight, headless-only browser from Google’s Chrome for Testing infrastructure. It has fewer system dependencies than full Chromium, making it a good fit for Docker containers and WSL environments.

WarningChromium (Deprecated)

The quarto install chromium command is deprecated. It transparently redirects to chrome-headless-shell — running quarto install chromium installs Chrome Headless Shell and automatically removes any legacy Chromium installation. CI pipelines using quarto install chromium --no-prompt continue to work without changes.

To install Chrome Headless Shell directly:

Terminal
quarto install chrome-headless-shell

This also automatically removes any legacy Puppeteer Chromium. The chromium tool will be removed from the registry in a future release.