# Dark mode

> How charts switch to dark: the darkMode setting, light and dark color pairs, and preset dark palettes.

Use the theme switch in the site header: every chart on this site redraws in its dark palette, including this one, which sets no dark colors of its own.

```json
{
  "mark": "bar",
  "data": [
    {
      "country": "India",
      "millions": 1463
    },
    {
      "country": "China",
      "millions": 1410
    },
    {
      "country": "United States",
      "millions": 347
    },
    {
      "country": "Indonesia",
      "millions": 285
    },
    {
      "country": "Pakistan",
      "millions": 255
    },
    {
      "country": "Nigeria",
      "millions": 240
    },
    {
      "country": "Brazil",
      "millions": 217
    },
    {
      "country": "Bangladesh",
      "millions": 175
    },
    {
      "country": "Russia",
      "millions": 144
    },
    {
      "country": "Ethiopia",
      "millions": 135
    }
  ],
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  }
}
```

## The darkMode setting

Dark mode is a host setting, not a spec field, because the page decides whether it is dark. Pass `darkMode` where the chart mounts:

```ts title="chart.ts"
createChart(container, spec, { darkMode: "force" });
```

React, Vue and Svelte take the same value as a `darkMode` prop on `<Chart>`, or once for every chart on `<VizThemeProvider>`.

| Value | Behavior |
| --- | --- |
| `"off"` | Always light. The default. |
| `"force"` | Always dark. |
| `"auto"` | Follows the reader's system setting through the `prefers-color-scheme` media query. |

`"auto"` does not see a site's own theme switch, such as a `dark` class on the page. If your site has a switch, pass `"force"` or `"off"` from its state. This site does that, and remounts each chart when the reader changes theme.

Without dark colors in the theme, the library derives them: it swaps the background and text colors, adjusts the brightness of the palette and lightens the gridlines.

## A preset's dark palette

```json
{
  "mark": "bar",
  "data": [
    {
      "country": "India",
      "millions": 1463
    },
    {
      "country": "China",
      "millions": 1410
    },
    {
      "country": "United States",
      "millions": 347
    },
    {
      "country": "Indonesia",
      "millions": 285
    },
    {
      "country": "Pakistan",
      "millions": 255
    },
    {
      "country": "Nigeria",
      "millions": 240
    },
    {
      "country": "Brazil",
      "millions": 217
    },
    {
      "country": "Bangladesh",
      "millions": 175
    },
    {
      "country": "Russia",
      "millions": 144
    },
    {
      "country": "Ethiopia",
      "millions": 135
    }
  ],
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#5e9fd6"
        },
        {
          "light": "#e3120b",
          "dark": "#f4655a"
        },
        {
          "light": "#7fb0d3",
          "dark": "#93c2e2"
        },
        {
          "light": "#e0a63b",
          "dark": "#e0b267"
        },
        {
          "light": "#3a8a6e",
          "dark": "#4fb093"
        },
        {
          "light": "#8c8680",
          "dark": "#9aa1a8"
        }
      ],
      "categoricalFill": [
        {
          "light": "#3b7097",
          "dark": "#80b5e3"
        },
        {
          "light": "#ee493a",
          "dark": "#ec5b50"
        },
        {
          "light": "#97c2e2",
          "dark": "#acd3eb"
        },
        {
          "light": "#efbb64",
          "dark": "#c6ad55"
        },
        {
          "light": "#579a81",
          "dark": "#5bd2ac"
        },
        {
          "light": "#9e9893",
          "dark": "#b4b9bf"
        }
      ],
      "background": {
        "light": "#fffdf9",
        "dark": "#12181f"
      },
      "text": {
        "light": "#1a1714",
        "dark": "#e9ebe6"
      },
      "gridline": {
        "light": "rgba(26,23,20,0.08)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "hairline": {
        "light": "rgba(26,23,20,0.28)",
        "dark": "rgba(233,235,230,0.28)"
      },
      "axis": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      },
      "annotationFill": {
        "light": "rgba(26,23,20,0.05)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "annotationText": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      }
    },
    "fonts": {
      "sizes": {
        "title": 24,
        "subtitle": 14,
        "body": 13,
        "small": 11
      }
    },
    "spacing": {
      "padding": 20,
      "chromeGap": 8,
      "chromeToChart": 16,
      "chartToFooter": 12
    },
    "chrome": {
      "eyebrow": {
        "color": {
          "light": "#e3120b",
          "dark": "#f4463f"
        },
        "fontSize": 11,
        "fontWeight": 700
      },
      "title": {
        "fontWeight": 700,
        "lineHeight": 1.18
      },
      "subtitle": {
        "fontWeight": 400,
        "lineHeight": 1.45
      }
    },
    "rule": {
      "color": {
        "light": "#e3120b",
        "dark": "#f4463f"
      },
      "width": 40,
      "thickness": 3
    },
    "borderRadius": 0
  }
}
```

Presets carry their own dark colors. Broadsheet's warm paper turns to an ink-blue night page, its text to a cool off-white, and its palette lifts to hold the same contrast: the red rule goes a shade lighter with it. Terminal is the exception: it is dark in both modes.

## Light and dark color pairs

```json
{
  "mark": "bar",
  "data": [
    {
      "year": "1900",
      "anomaly": -0.08,
      "trend": "Cooler"
    },
    {
      "year": "1910",
      "anomaly": -0.43,
      "trend": "Cooler"
    },
    {
      "year": "1920",
      "anomaly": -0.27,
      "trend": "Cooler"
    },
    {
      "year": "1930",
      "anomaly": -0.16,
      "trend": "Cooler"
    },
    {
      "year": "1940",
      "anomaly": 0.12,
      "trend": "Warmer"
    },
    {
      "year": "1950",
      "anomaly": -0.17,
      "trend": "Cooler"
    },
    {
      "year": "1960",
      "anomaly": -0.03,
      "trend": "Cooler"
    },
    {
      "year": "1970",
      "anomaly": 0.03,
      "trend": "Warmer"
    },
    {
      "year": "1980",
      "anomaly": 0.26,
      "trend": "Warmer"
    },
    {
      "year": "1990",
      "anomaly": 0.45,
      "trend": "Warmer"
    },
    {
      "year": "2000",
      "anomaly": 0.39,
      "trend": "Warmer"
    },
    {
      "year": "2010",
      "anomaly": 0.72,
      "trend": "Warmer"
    },
    {
      "year": "2020",
      "anomaly": 1.01,
      "trend": "Warmer"
    },
    {
      "year": "2025",
      "anomaly": 1.19,
      "trend": "Warmer"
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "title": "Year",
        "format": "%Y"
      }
    },
    "y": {
      "field": "anomaly",
      "type": "quantitative",
      "axis": {
        "title": "Difference from the 1951–1980 average (°C)",
        "format": "+.1f"
      }
    },
    "color": {
      "field": "trend",
      "type": "nominal",
      "scale": {
        "domain": [
          "Cooler",
          "Warmer"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "strokeWidth": 1
    }
  ],
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#7fb0d3"
        },
        {
          "light": "#c2410c",
          "dark": "#fb923c"
        }
      ],
      "background": {
        "light": "#fff8ef",
        "dark": "#17130f"
      },
      "text": {
        "light": "#2b2118",
        "dark": "#f3e9dc"
      },
      "axis": {
        "light": "#76695b",
        "dark": "#b3a493"
      }
    }
  },
  "chrome": {
    "title": "Global temperature has been above the 1951–1980 average in every reading since 1970",
    "subtitle": "Global surface temperature, difference from the 1951–1980 average (°C), by decade from 1900, plus 2025"
  }
}
```

Any single color in a theme can be a `{ light, dark }` pair. The library then uses your dark value instead of deriving one, which is how you keep brand colors exact in both modes. This chart sets pairs for the background, the text, the axis and both series colors:

```ts title="theme.ts"
const theme = {
  colors: {
    categorical: [
      { light: "#1d5f8a", dark: "#7fb0d3" },
      { light: "#c2410c", dark: "#fb923c" },
    ],
    background: { light: "#fff8ef", dark: "#17130f" },
    text: { light: "#2b2118", dark: "#f3e9dc" },
    axis: { light: "#76695b", dark: "#b3a493" },
  },
};
```

Pairs replace whole when themes merge, so a later theme layer that sets `background` replaces both of its values.

## Fields that matter

| Field | What it does |
| --- | --- |
| `darkMode` (mount option or prop) | `"off"`, `"force"` or `"auto"`. |
| `theme.colors.*` as `{ light, dark }` | Sets the dark value of one color yourself. |
| `theme.colors.categorical` | A list of colors or pairs, one per series. |

## Related

- [Theming and tokens](/docs/style/theming/) covers every theme field.
- [Presets](/docs/style/presets/) shows all four presets in light mode.
- [Bar](/docs/comparison/bar/) covers the bar charts on this page.
- [Theme reference](/docs/spec/theme/#darkmode) documents `DarkMode` and how the dark theme is derived.
