Home

Diagrams

Usage

Start with these tokens when customizing diagrams:

  • --diagram-base-color and --diagram-base-color-dark to shift the entire palette

  • --diagram-background and --diagram-text-color for overall contrast

  • --diagram-node-background and --diagram-node-border-color for shapes

  • --diagram-edge-color and --diagram-edge-width for connections

Most diagram colors derive from --diagram-base-color (defaults to --color-accent), so changing it re-tints nodes, edges, and text together. Set tokens on :root in your theme CSS so JS renderers can read them.

Tokens

Base Color Token

The foundation token from which all diagram colors are calculated.

TokenDescriptionDefault Value
--diagram-base-colorBase color for all diagram color calculationsvar(--color-accent)
--diagram-base-color-darkBase color for dark modevar(--color-accent-dark)

Core Diagram Tokens

Base styling tokens that apply to all diagram types.

TokenDescriptionDefault Value
--diagram-backgroundBackground color for diagramsvar(--surface-elevated)
--diagram-background-darkBackground color in dark modevar(--surface-elevated-dark)
--diagram-font-familyFont family for diagram textvar(--font-family-sans)
--diagram-font-sizeFont size for diagram textcalc(var(--text-font-size) * 0.9)
--diagram-text-colorPrimary text colorcolor-mix(in srgb, var(--diagram-base-color) 95%, var(--diagram-background))
--diagram-text-color-darkPrimary text color in dark modecolor-mix(in srgb, var(--diagram-base-color-dark) 95%, var(--diagram-background-dark))

Node and Shape Tokens

Colors and styling for diagram nodes, shapes, and containers. All colors calculated from --diagram-base-color mixed with --diagram-background.

TokenDescriptionCalculation
--diagram-node-backgroundPrimary node/shape fill colorcolor-mix(in srgb, var(--diagram-base-color) 15%, var(--diagram-background))
--diagram-node-background-secondarySecondary node backgroundcolor-mix(in srgb, var(--diagram-base-color) 25%, var(--diagram-background))
--diagram-node-background-tertiaryTertiary node background (3+ states)color-mix(in srgb, var(--diagram-base-color) 35%, var(--diagram-background))
--diagram-node-border-colorNode border colorcolor-mix(in srgb, var(--diagram-base-color) 35%, var(--diagram-background))
--diagram-node-border-widthNode border widthvar(--border-width-thick)
--diagram-node-text-colorText color inside nodesvar(--diagram-text-color)

Edge and Connection Tokens

Styling for lines, arrows, and connections between diagram nodes.

TokenDescriptionCalculation
--diagram-edge-colorLine/edge colorcolor-mix(in srgb, var(--diagram-base-color) 60%, var(--diagram-background))
--diagram-edge-widthLine/edge widthvar(--border-width-default)
--diagram-edge-text-colorEdge label text colorvar(--diagram-text-color)

State Tokens

Generic state tokens applicable across diagram types (Gantt tasks, state diagrams, etc.).

TokenDescriptionDefault Value
--diagram-active-backgroundBackground for active statesvar(--diagram-node-background-tertiary)
--diagram-active-border-colorBorder for active statesvar(--diagram-node-border-color)
--diagram-inactive-backgroundBackground for inactive/default statesvar(--diagram-node-background)
--diagram-inactive-border-colorBorder for inactive/default statesvar(--diagram-node-border-color)
--diagram-complete-backgroundBackground for completed statesvar(--diagram-node-background-secondary)
--diagram-complete-border-colorBorder for completed statesvar(--diagram-node-border-color)

Structure Tokens

Tokens for structural diagram elements like grids, sections, and groupings.

TokenDescriptionCalculation
--diagram-grid-colorGrid line colorvar(--diagram-base-color)

Examples

These examples demonstrate how the theming system applies across different Mermaid diagram types. Each example tests different aspects of the token system.

Default Diagrams

Standard diagram styling with default theme tokens:

:root {
  /* No design token overrides */
}

Tests node backgrounds, decision diamonds, edge colors, and edge labels.

Sequence Diagram

Tests actor backgrounds/borders, signal colors, and activation boxes (uses secondary background).

State Diagram

Tests state node backgrounds, transition colors, and special state indicators. Uses --diagram-node-background variants for different states.

Class Diagram

Tests node hierarchy with different visibility levels using primary/secondary/tertiary backgrounds.

Entity Relationship Diagram

Tests entity boxes, relationship lines, and cardinality labels.

Gantt Chart

Tests timeline bars using --diagram-node-background variants for different task states (done/active/future).

Cytoscape Network Graph

Tests node styling, edge styling, and state selectors (selected nodes use active colors).

Tips

Hierarchy: Use --diagram-node-background, --diagram-node-background-secondary, and --diagram-node-background-tertiary to differentiate node states or groups.

Edges: Adjust --diagram-edge-color and --diagram-edge-width together so connectors stay legible against node fills.

Text overrides: Leave --diagram-text-color as the base and override --diagram-node-text-color only when you need extra contrast.

Renderer parity: Mermaid and Cytoscape both read the same tokens, so keep customizations in token space instead of tool-specific CSS.

© 2026 Stencila