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