Theming
Use CSS to apply colors, fonts, and other styles.
Pele uses CSS variables for colors and fonts, with class names for styling individual elements.
Switch between light and dark colors without re-rendering the diagram.
Variables
| Variable | Default | Used for |
|---|---|---|
--pele-bg | #ffffff | Backgrounds |
--pele-fg | #1f1f1f | Text |
--pele-fg-on-light | #1f1f1f | Text on light fills set in the source |
--pele-fg-on-dark | #ffffff | Text on dark fills set in the source |
--pele-muted | #6e6e6e | Secondary text |
--pele-line | #1f1f1f | Edges and arrowheads |
--pele-surface | #f3f3f3 | Node fill |
--pele-surface-alt | #e6e6e6 | Subgraph fill |
--pele-border | #8a8a8a | Node and subgraph borders |
--pele-accent | #5b7bd5 | Highlights |
--pele-critical | #e45756 | Critical tasks in a Gantt chart, high priorities in a kanban |
--pele-error | #e45756 | Errors that mount() shows |
--pele-font | Measured font | Label font. See Fonts |
--pele-font-mono | Measured font | Monospace labels |
--pele-title-weight | bold | Diagram title |
--pele-heading-weight | bold | Headings inside a diagram, such as class names and section labels |
--pele-bold-weight | bold | Bold text in labels |
--pele-radius | 4px | Corner radius of rounded shapes |
Series colors
Charts and color-coded categories use --pele-series-1 through --pele-series-8. Colors repeat after the eighth category.
| Variable | Default |
|---|---|
--pele-series-1 | #4c78a8 |
--pele-series-2 | #f58518 |
--pele-series-3 | #54a24b |
--pele-series-4 | #e45756 |
--pele-series-5 | #72b7b2 |
--pele-series-6 | #eeca3b |
--pele-series-7 | #b279a2 |
--pele-series-8 | #9d755d |
For example, pie charts use a color for each slice, and git graphs use a color for each branch. Some shapes use --pele-bg for their text, so choose series colors that contrast with it.
Setting variables
Set the variables on the root <svg> or on any element that contains it. The root of every diagram has the class pele.
1.pele {2 --pele-bg: #fffcf0;3 --pele-fg: #100f0f;4 --pele-muted: #6f6e69;5 --pele-line: #100f0f;6 --pele-surface: #f2f0e5;7 --pele-surface-alt: #e6e4d9;8 --pele-border: #cecdc3;9 --pele-accent: #205ea6;10 --pele-critical: #af3029;11}1213@media (prefers-color-scheme: dark) {14 .pele {15 --pele-bg: #100f0f;16 --pele-fg: #cecdc3;17 --pele-muted: #878580;18 --pele-line: #cecdc3;19 --pele-surface: #1c1b1a;20 --pele-surface-alt: #282726;21 --pele-border: #403e3c;22 --pele-accent: #4385be;23 --pele-critical: #d14d41;24 }25}Fonts
Pele measures labels to size nodes, so it needs the font before rendering.
mount() reads --pele-font and --pele-font-mono from CSS. Without these variables, it uses the container font for regular text and monospace for monospace text.
1.diagram {2 --pele-font: var(--font-text);3 --pele-font-mono: var(--font-monospace);4}Call refresh() after changing fonts so Pele can measure the labels again. mount() also redraws after pending web fonts load.
With render(), pass the font through fontFamily:
1const fontFamily = getComputedStyle(container).fontFamily;2container.innerHTML = render(source, { fontFamily }).svg;If you also set --pele-font in CSS, use the same font so the labels fit their measured size.
To draw part of a diagram in the monospace font, list it in monospace instead of styling it with CSS alone, so Pele measures it in that font and makes room for it. Text with a font-family set by style or classDef keeps that font.
1render(source, { monospace: ['members'] });| Part | Text |
|---|---|
members | Attributes and methods in class diagrams, styled by .pele-member |
attributes | Attribute types, names and keys in ER diagrams, styled by .pele-er-type, .pele-er-name and .pele-er-keys |
files | File and directory names in tree view diagrams, styled by .pele-label inside .pele-tree-file and .pele-tree-dir |
messages | Message text on arrows in sequence diagrams, styled by .pele-edge-label |
Classes
Elements in the SVG have class names. Use them to style one kind of element without changing a variable.
| Class | Element |
|---|---|
pele | The root <svg> of every diagram |
pele-flowchart | The root <svg> of a flowchart |
pele-title | The diagram title |
pele-node | The group that holds a node’s shape and label |
pele-edge | The group that holds an edge’s line and markers |
pele-edge-label | The label on an edge |
pele-cluster | A subgraph |
pele-cluster-label | The title of a subgraph |
pele-label | The text of a node label |
pele-marker | An arrowhead or other edge marker |
pele-icon | An icon |
pele-math | A math expression |
Use data-id to target a node by its source id:
1.pele-node[data-id="start"] .pele-label {2 fill: var(--pele-accent);3}Styles in the diagram
Diagram styles can override theme colors. For example:
1flowchart LR2 A[Draft] --> B[Review]:::warn --> C[Done]3 style C fill:#879a39,stroke:#66800b,color:#fffcf04 classDef warn fill:#d0a215,stroke:#ad83015 linkStyle 0 stroke:#878580,stroke-dasharray:4 4Colors set this way are fixed. They do not change with the theme.
A diagram can define fill colors with style, classDef, or a sequence rect or box. Labels on a fill automatically use whichever of --pele-fg-on-light and --pele-fg-on-dark contrasts more with it.
Series palettes
Mermaid’s palette theme variables replace the --pele-series-* colors in a diagram. Pele reads only the first eight colors of each palette:
| Diagram | Theme variables |
|---|---|
| XY chart | xyChart.plotColorPalette, a comma-separated list |
| Pie chart | pie1 to pie8 |
| Git graph | git0 to git7 |
| Timeline, radar, treemap | cScale0 to cScale7 |
| Mindmap | cScale1 to cScale8 |
| Venn diagram | venn1 to venn8 |
1---2config:3 themeVariables:4 xyChart:5 plotColorPalette: "#205ea6, #bc5215"6---7xychart8 x-axis [jan, feb, mar]9 bar [3, 5, 2]10 line [2, 4, 3]Palette colors are fixed, like other styles in the diagram. They don’t change with the theme. To follow the theme, use a Pele CSS variable such as var(--pele-accent) as a palette color. Only --pele-* variables work. Labels on a palette color use whichever of --pele-fg-on-light and --pele-fg-on-dark contrasts more with it. Other themeVariables colors don’t apply.