Theming

Use CSS to apply colors, fonts, and other styles.

View Markdown

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

VariableDefaultUsed for
--pele-bg#ffffffBackgrounds
--pele-fg#1f1f1fText
--pele-fg-on-light#1f1f1fText on light fills set in the source
--pele-fg-on-dark#ffffffText on dark fills set in the source
--pele-muted#6e6e6eSecondary text
--pele-line#1f1f1fEdges and arrowheads
--pele-surface#f3f3f3Node fill
--pele-surface-alt#e6e6e6Subgraph fill
--pele-border#8a8a8aNode and subgraph borders
--pele-accent#5b7bd5Highlights
--pele-critical#e45756Critical tasks in a Gantt chart, high priorities in a kanban
--pele-error#e45756Errors that mount() shows
--pele-fontMeasured fontLabel font. See Fonts
--pele-font-monoMeasured fontMonospace labels
--pele-title-weightboldDiagram title
--pele-heading-weightboldHeadings inside a diagram, such as class names and section labels
--pele-bold-weightboldBold text in labels
--pele-radius4pxCorner 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.

VariableDefault
--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.

.pele {  --pele-bg: #fffcf0;  --pele-fg: #100f0f;  --pele-muted: #6f6e69;  --pele-line: #100f0f;  --pele-surface: #f2f0e5;  --pele-surface-alt: #e6e4d9;  --pele-border: #cecdc3;  --pele-accent: #205ea6;  --pele-critical: #af3029;}@media (prefers-color-scheme: dark) {  .pele {    --pele-bg: #100f0f;    --pele-fg: #cecdc3;    --pele-muted: #878580;    --pele-line: #cecdc3;    --pele-surface: #1c1b1a;    --pele-surface-alt: #282726;    --pele-border: #403e3c;    --pele-accent: #4385be;    --pele-critical: #d14d41;  }}

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.

.diagram {  --pele-font: var(--font-text);  --pele-font-mono: var(--font-monospace);}

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:

const fontFamily = getComputedStyle(container).fontFamily;container.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.

render(source, { monospace: ['members'] });
PartText
membersAttributes and methods in class diagrams, styled by .pele-member
attributesAttribute types, names and keys in ER diagrams, styled by .pele-er-type, .pele-er-name and .pele-er-keys
filesFile and directory names in tree view diagrams, styled by .pele-label inside .pele-tree-file and .pele-tree-dir
messagesMessage 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.

ClassElement
peleThe root <svg> of every diagram
pele-flowchartThe root <svg> of a flowchart
pele-titleThe diagram title
pele-nodeThe group that holds a node’s shape and label
pele-edgeThe group that holds an edge’s line and markers
pele-edge-labelThe label on an edge
pele-clusterA subgraph
pele-cluster-labelThe title of a subgraph
pele-labelThe text of a node label
pele-markerAn arrowhead or other edge marker
pele-iconAn icon
pele-mathA math expression

Use data-id to target a node by its source id:

.pele-node[data-id="start"] .pele-label {  fill: var(--pele-accent);}

Styles in the diagram

Diagram styles can override theme colors. For example:

flowchart LR  A[Draft] --> B[Review]:::warn --> C[Done]  style C fill:#879a39,stroke:#66800b,color:#fffcf0  classDef warn fill:#d0a215,stroke:#ad8301  linkStyle 0 stroke:#878580,stroke-dasharray:4 4

Colors 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:

DiagramTheme variables
XY chartxyChart.plotColorPalette, a comma-separated list
Pie chartpie1 to pie8
Git graphgit0 to git7
Timeline, radar, treemapcScale0 to cScale7
MindmapcScale1 to cScale8
Venn diagramvenn1 to venn8
---config:  themeVariables:    xyChart:      plotColorPalette: "#205ea6, #bc5215"---xychart  x-axis [jan, feb, mar]  bar [3, 5, 2]  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.