🎨 Live Theme Toggle
Use the toggle in the header to switch between light and dark mode. The toggle sets data-theme on
the page, which swaps the CSS custom properties defined on the chart's container, and then calls
gantt.update({ theme }) so the chart renders again with the new values. Token values are read
when the chart renders: changing them alone does not repaint a chart that is already on screen.
📋 How it works
Set CSS custom properties on the container element (or any ancestor) to override the default JS option values.
The chart reads them when it renders, so after changing them (a theme switch, a class toggle, an OS dark-mode
change picked up with matchMedia) call gantt.update(). Colors set on individual
tasks still take precedence over the tokens.
/* Light mode tokens on the container */ #my-gantt { --apex-gantt-bar-fill: #87B7FE;
--apex-gantt-row-bg-even: #ffffff; --apex-gantt-row-bg-odd: #f5f9ff; --apex-gantt-header-bg: #ebf3fb;
--apex-gantt-grid-line: #e3edf8; --apex-gantt-dependency-line: #1a6fc4; --apex-gantt-font-family: system-ui,
sans-serif; --apex-gantt-font-size: 13px; --apex-gantt-font-color: #2d3748; } /* Dark mode from the OS
preference, read when the chart renders */ @media (prefers-color-scheme: dark) { #my-gantt {
--apex-gantt-bar-fill: #818cf8; --apex-gantt-background-color: #1e1e1e; --apex-gantt-row-bg-even: #1e1e1e;
--apex-gantt-row-bg-odd: #252525; --apex-gantt-header-bg: #2a2a2a; --apex-gantt-grid-line: #3a3a3a;
--apex-gantt-dependency-line: #a5b4fc; --apex-gantt-font-color: #e0e0e0; } } /* Dark mode from a manual
[data-theme] toggle, followed by gantt.update({ theme: 'dark' }) */ [data-theme="dark"] #my-gantt {
--apex-gantt-bar-fill: #818cf8; --apex-gantt-background-color: #1e1e1e; --apex-gantt-row-bg-even: #1e1e1e;
--apex-gantt-row-bg-odd: #252525; --apex-gantt-dependency-line: #a5b4fc; --apex-gantt-font-color: #e0e0e0;
}
📖 Token Reference
All supported CSS custom properties for ApexGantt.