🎨 Live Theme Toggle

Use the toggle in the header to switch between light and dark mode. The Sankey diagram responds to CSS custom properties defined on its container element. No JavaScript options are changed: the toggle flips a class and calls refreshTokens(), which repaints with the new values and keeps every node where it is.

🌑 Dark Mode via prefers-color-scheme

This chart is themed entirely via a CSS @media (prefers-color-scheme: dark) block. The diagram reads its variables when it renders, so one matchMedia listener calls refreshTokens() when the OS appearance changes. Switch your OS appearance to dark mode to see it update.

📋 How it works

Set CSS custom properties on the container element (or any ancestor) to replace the default values of options you leave out. An option you pass beats its variable (from ApexSankey 1.14.0), so this demo passes no color, opacity or gradient options. The chart reads the variables when it renders; after changing them, call refreshTokens().

/* Light mode tokens on the container */ #my-sankey { --apex-sankey-edge-opacity: 0.5; --apex-sankey-edge-gradient: true; --apex-sankey-label-color: #2d3748; --apex-sankey-label-font-size: 12px; --apex-sankey-font-family: system-ui, sans-serif; --apex-sankey-node-border-color: transparent; --apex-sankey-node-border-width: 0; /* tooltipTheme sets the tooltip bg + border + text color together */ --apex-sankey-tooltip-theme: light; } /* Dark mode, via OS preference (one matchMedia listener, below). One token flips the whole tooltip to a readable dark preset. */ @media (prefers-color-scheme: dark) { #my-sankey { --apex-sankey-edge-opacity: 0.4; --apex-sankey-label-color: #c9d1d9; --apex-sankey-tooltip-theme: dark; } } /* Dark mode, via a manual [data-theme] toggle */ [data-theme="dark"] #my-sankey { --apex-sankey-edge-opacity: 0.4; --apex-sankey-label-color: #c9d1d9; --apex-sankey-tooltip-theme: dark; } /* Repaint after a change that does not render the chart */ toggle.onclick = () => { const b = document.body; b.dataset.theme = b.dataset.theme === 'dark' ? '' : 'dark'; sankey.refreshTokens(); }; matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => sankey.refreshTokens());

📖 Token Reference

All supported CSS custom properties for ApexSankey.

--apex-sankey-edge-opacity
Flow edge opacity (0-1, default 0.4)
--apex-sankey-edge-gradient
Edge gradient fill ('true'/'false', default true)
--apex-sankey-label-color
Node label text color
--apex-sankey-label-font-size
Node label font size (e.g. 12px)
--apex-sankey-font-family
Font family for all labels
--apex-sankey-node-width
Drawn node width in px (default 20). The layout keeps the nodeWidth option, so keep the two equal
--apex-sankey-node-border-color
Node border color (default: node color)
--apex-sankey-node-border-width
Node border width in px (default 1)
--apex-sankey-tooltip-bg
Tooltip background color (default #FFFFFF)
--apex-sankey-tooltip-border-color
Tooltip border color (default #E2E8F0)
--apex-sankey-tooltip-font-color
Tooltip text color (default #1a1a1a)
--apex-sankey-tooltip-theme
'light' | 'dark': preset for tooltip bg + border + text (the tooltip color variables still win)
--apex-sankey-focus-color
Keyboard focus ring (default #005FCC, from 1.14.0)
--apex-sankey-particle-color
particleFlow particles (default rgba(255,255,255,0.9), from 1.14.0)