Mermaid Graphics
Material for MkDocs provides its own built-in, native integration for Mermaid.js, rendering external python plugins unnecessary for standard diagram support. Material for MkDocs automatically handles the initialization and styling of Mermaid diagrams out of the box. The built-in integration automatically adjusts diagram fonts and colors to match your selected light or dark theme palettes.
Warning
Using the third-party mkdocs-mermaid2-plugin alongside Material for MkDocs can break dynamic dark mode switching and is incompatible with the mkdocs-minify-plugin.
To use the native diagram system, simply enable its JavaScript markdown extension in your mkdocs.yml file:
markdown_extensions:
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_code_format
Mermaid2 JavaScript version 10.4.0
Example Pie Chart
Pets Adopted
%%{init: { 'theme': 'base', 'themeVariables': { 'pie1': '#ff9999', 'pie2': '#66b2ff', 'pie3': '#99ff99', 'pieTitleTextColor': '#66b2ff' }}}%%
pie showData title My Pie Chart
"Dogs" : 386
"Cats" : 85
"Rabbits" : 15
"Rats" : 12
<h3 style="text-align: center;">Pets Adopted</h3>
```mermaid
pie showData
"Dogs" : 386
"Cats" : 85
"Rabbits" : 15
"Rats" : 12
```
graph TD
A[Client] --> B[Load Balancer]
B --> C[Server01]
B --> D[Server02]
B --> E[Server03]
```mermaid
graph TD
A[Client] --> B[Load Balancer]
B --> C[Server01]
B --> D[Server02]
B --> E[Server03]
```
%%{init: { "themeVariables": {"xyChart": {"backgroundColor": "#808080"} } }}%%
xychart-beta
title "Sales Revenue"
x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
y-axis "Revenue (in $)" 4000 --> 11000
bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
See: CSS to change the background colour of XY chart from mermaid.js