Tooltips
The background, text, border, corners and shadow of the tooltip, and the lines and text of the crosshair.
Where to set the variables
The tooltip is not inside the chart in the page: there is one tooltip for the whole page, at the end of the page. So it reads the variables of the chart when it opens. They can be set on the chart, on a class or on :root, as other variables. The font, the text size and the colour scheme come from the chart too.
The charts on this page show all their numbers, so they have data-chart-tooltip="true" to have a tooltip anyway. If you hover over them (or tap them on a touch device), the tooltip shows. See Tooltips for what a tooltip shows.
The variables
| Variable | Sets |
|---|---|
--tablechart-tooltip-surface |
The background: white by default, and in dark mode the chart's background |
--tablechart-tooltip-color |
The text colour: the chart's text colour by default |
--tablechart-tooltip-border |
The border: a thin line in the text colour by default |
--tablechart-tooltip-radius |
The corners: 0.4em by default |
--tablechart-tooltip-padding |
The space inside the tooltip: 0.45em 0.7em by default |
--tablechart-tooltip-shadow |
The shadow under the tooltip, so it stands out from what is behind it |
A dark tooltip
A dark tooltip stands out on a light page. The dots before the names keep the colours of the lines or columns, so check that they show on the dark background.
.dark-tooltip {
--tablechart-tooltip-surface: #16323f;
--tablechart-tooltip-color: #f3efe9;
--tablechart-tooltip-border: none;
--tablechart-color-1: #65941c;
--tablechart-color-2: #b47a2a;
}
| Year | Farm shop | Market |
|---|---|---|
| 2023 | 64 | 38 |
| 2024 | 71 | 45 |
| 2025 | 69 | 57 |
<figure class="dark-tooltip" data-chart="column" data-chart-tooltip="true">
<table>
<thead>
<tr><th>Year</th><th>Farm shop</th><th>Market</th></tr>
</thead>
<tbody>
<tr><th>2023</th><td>64</td><td>38</td></tr>
<tr><th>2024</th><td>71</td><td>45</td></tr>
<tr><th>2025</th><td>69</td><td>57</td></tr>
</tbody>
</table>
</figure>
A flat tooltip
Without a shadow, a border in the colour of the chart sets the tooltip apart. Square corners and more padding make it a small card.
.flat-tooltip {
--tablechart-tooltip-shadow: none;
--tablechart-tooltip-border: 2px solid #2f6f7e;
--tablechart-tooltip-radius: 0;
--tablechart-tooltip-padding: 0.6em 0.9em;
}
| Year | North | South |
|---|---|---|
| 2016 | 41 | 30 |
| 2019 | 58 | 39 |
| 2022 | 77 | 52 |
| 2025 | 105 | 61 |
<figure class="flat-tooltip" data-chart="line" data-chart-legend data-chart-tooltip="true">
<table>
<thead>
<tr><th>Year</th><th>North</th><th data-line="dashed">South</th></tr>
</thead>
<tbody>
<tr><th>2016</th><td>41</td><td>30</td></tr>
<tr><th>2019</th><td>58</td><td>39</td></tr>
<tr><th>2022</th><td>77</td><td>52</td></tr>
<tr><th>2025</th><td>105</td><td>61</td></tr>
</tbody>
</table>
</figure>
Crosshair
A line or area chart with data-chart-tooltip="crosshair" has a crosshair instead of a tooltip. See Crosshair. Its lines and its labels have variables. Unlike the tooltip, the crosshair is inside the chart, so the variables work as all other variables of the chart.
| Variable | Sets |
|---|---|
--tablechart-crosshair-color |
The colour of the lines: the text colour, half see-through, by default |
--tablechart-crosshair-width |
How thick the lines are: 1px by default |
--tablechart-crosshair-size |
The size of the values and the name of the row. By default, the values are as big as the numbers of the axis, and the name as the names under the chart, so their text covers those. |
--tablechart-crosshair-radius |
The corners of the values and the name of the row: 0.25em by default |
--tablechart-crosshair-padding |
The space inside the values and the name of the row: 0.1em 0.25em by default |
--tablechart-crosshair-border |
The border of the values and the name of the row: 1px in the background colour by default, so they stand apart from the lines and numbers under them |
--tablechart-crosshair-name-surface |
The background of the name of the row: the text colour of the chart by default |
--tablechart-crosshair-name-color |
The text of the name of the row: the background colour by default |
Each value has the colour of its line, so --tablechart-color-1 and the other colours of the lines set those. Its text gets to be black or white, whichever has more contrast.
.bold-crosshair {
--tablechart-crosshair-color: #b47a2a;
--tablechart-crosshair-width: 2px;
--tablechart-crosshair-size: 1em;
--tablechart-crosshair-radius: 0;
--tablechart-crosshair-name-surface: #b47a2a;
--tablechart-crosshair-name-color: #fff;
}
| Year | North | South |
|---|---|---|
| 2016 | 41 | 30 |
| 2017 | 47 | 33 |
| 2018 | 52 | 36 |
| 2019 | 58 | 39 |
| 2020 | 63 | 44 |
| 2021 | 70 | 47 |
| 2022 | 77 | 52 |
| 2023 | 86 | 55 |
| 2024 | 94 | 58 |
| 2025 | 105 | 61 |
<figure class="bold-crosshair" data-chart="line" data-chart-tooltip="crosshair" data-chart-values="none" data-chart-axis data-chart-legend>
<table>
<thead>
<tr><th>Year</th><th>North</th><th data-line="dashed">South</th></tr>
</thead>
<tbody>
<tr><th>2016</th><td>41</td><td>30</td></tr>
<tr><th>2017</th><td>47</td><td>33</td></tr>
<tr><th>2018</th><td>52</td><td>36</td></tr>
<tr><th>2019</th><td>58</td><td>39</td></tr>
<tr><th>2020</th><td>63</td><td>44</td></tr>
<tr><th>2021</th><td>70</td><td>47</td></tr>
<tr><th>2022</th><td>77</td><td>52</td></tr>
<tr><th>2023</th><td>86</td><td>55</td></tr>
<tr><th>2024</th><td>94</td><td>58</td></tr>
<tr><th>2025</th><td>105</td><td>61</td></tr>
</tbody>
</table>
</figure>
Light and dark
The tooltip follows the colour scheme of the chart. If you want to set a colour for each scheme, use light-dark() in a variable, as for the chart itself. See Light and dark.
:root {
--tablechart-tooltip-surface: light-dark(#ffffff, #16323f);
--tablechart-tooltip-color: light-dark(#16323f, #f3efe9);
}
Next
See CSS variables for all variables.