Font

All text in a chart is HTML, so it uses the font of the page. If you want to use another font in a chart, set font-family on it.

Sizes

--tablechart-font-size sets the size of all text in a chart: 1em by default. The other sizes are relative to it.

CSS
.sizes {
	--tablechart-value-size: 2em;
	--tablechart-name-size: 0.75em;
}
Spring 58
Summer 72
Autumn 70
Winter 91
HTML
<figure class="sizes" data-chart="column">
	<table>
		<tbody>
			<tr><th>Spring</th><td>58</td></tr>
			<tr><th>Summer</th><td>72</td></tr>
			<tr><th>Autumn</th><td>70</td></tr>
			<tr><th>Winter</th><td>91</td></tr>
		</tbody>
	</table>
</figure>
Variable Sets
--tablechart-font-size All text in a chart: 1em by default.
--tablechart-name-size All names, under the bars and beside the lines: 0.95em by default.
--tablechart-value-size The numbers on the bars: 1.3 times the names by default.
--tablechart-centre-size The central value of a donut: 1.6em by default.
--tablechart-caption-align The alignment of the title: left by default.
--tablechart-caption-gap The space under the title: 0.5em by default.

Text colours

By default, all text in a chart has the text colour of the chart. If you want to give some of it another colour, set one of these variables.

Variable Sets
--tablechart-name-color The names of the rows, under the columns or beside the bars
--tablechart-value-color The numbers on and after the bars, not inside them
--tablechart-axis-text-color The numbers and titles along the axes. See Axes and gridlines.

Numbers inside bars or columns

A number inside a bar or column needs a contrast of at least 4.5:1 with it, as text does. Tablechart aims for 5:1, so the number is easier to read.

By default, a number has the background colour of the chart, so it looks cut out of the bar, or the text colour of the chart:

Number on a dark bar Number on a light bar
Light background The background colour The text colour
Dark background The text colour The background colour
Set with --tablechart-value-on-dark --tablechart-value-on-light

Tablechart measures the background colour. See Background.

For each number, Tablechart takes the one of these two colours that has more contrast with its bar, its part of a stack or its step of a waterfall. If that has less than 5:1, the number gets to be black or white instead, whichever reaches 5:1. On a middle colour, where neither does but both reach 4.5:1, it gets to be white, because white is easier to read there. If the colours of the page change, such as from light to dark mode, the numbers get their colour again.

If you want other colours, such as those of your brand, set --tablechart-value-on-dark for the numbers on dark bars, and --tablechart-value-on-light for the numbers on light bars. They replace the two default colours. The contrast is checked in the same way: if your colour has less than 5:1 with a bar, the number on that bar gets to be black or white, to achieve better contrast. If you want another goal than 5:1, set --tablechart-value-contrast, such as 7 for 7:1. With APCA, the goal is Lc 60, and the setting is an Lc value, such as 75. See Contrast.

The contrast can be measured in two ways: as WCAG 2 does, with a ratio, or with APCA, with an Lc value. WCAG 2 is the default. If you want APCA, set --tablechart-contrast-wcag to 3. The dropdown in this example switches between the two. See Contrast.

How do visitors rate each apple?
% of votes
Variety Love it Like it Fine Not keen Dislike it
Elstar 34 22 18 14 12
Jonagold 28 25 20 15 12
Granny Smith 18 20 24 20 18

The text colour of this chart is changed to deep blue, so it is easy to tell apart from black. That is only for this demo. The numbers have no colour set. Each number gets the pink of the card or the deep blue text colour, whichever has 5:1. On the red parts, that is the pink. On the blue parts, it is the deep blue. On the green and purple parts, neither has 5:1, so the numbers get to be white. On the amber parts, they get to be black.

The text colour of this chart is changed to yellow, so it is easy to tell apart from white. That is only for this demo. The numbers have no colour set. Each number gets the dark pink of the card or the yellow text colour, whichever has 5:1. On the red parts, that is the yellow. On the blue parts, it is the dark pink. On the green and purple parts, neither has 5:1, so the numbers get to be white. On the amber parts, they get to be black.

The text colour of this chart is changed to deep blue, so it is easy to tell apart from black. That is only for this demo. The numbers have no colour set. With --tablechart-contrast-wcag: 3, each number gets the pink of the card or the deep blue text colour, whichever has Lc 60. On the red, green, amber and purple parts, that is the pink. On the blue parts, neither has Lc 60, so the numbers get to be white.

The text colour of this chart is changed to yellow, so it is easy to tell apart from white. That is only for this demo. The numbers have no colour set. With --tablechart-contrast-wcag: 3, each number gets the dark pink of the card or the yellow text colour, whichever has Lc 60. On the red, green, amber and purple parts, that is the yellow. On the blue parts, neither has Lc 60, so the numbers get to be white.

--tablechart-value-align sets where a number inside its bar goes: start, where the bar starts, center, or end, where it ends. On a waterfall, a step down ends at the bottom. The number is as far from the start or end as the widest number is from the sides. Columns and bars use end by default, a waterfall center.

CSS
.inside-start {
	--tablechart-value-align: start;
}
Spring 58
Summer 72
Autumn 70
Winter 91
HTML
<figure class="inside-start" data-chart="column" data-chart-labels="inside">
	<table>
		<tbody>
			<tr><th>Spring</th><td>58</td></tr>
			<tr><th>Summer</th><td>72</td></tr>
			<tr><th>Autumn</th><td>70</td></tr>
			<tr><th>Winter</th><td>91</td></tr>
		</tbody>
	</table>
</figure>

Smaller text on narrow charts

With many columns on a narrow screen, smaller text lets more numbers fit. Short names under the chart help too: see Many rows. If the element around the chart is a container, --tablechart-name-size can use clamp() and cqi, a share of the width of the container. The numbers are 1.3 times the name size, so they follow. In this example, the names and numbers are full size from 500px wide, and get smaller below that, down to 75%. The title keeps its size.

CSS
.text-box {
	container-type: inline-size;
}
.text-box > [data-chart] {
	--tablechart-name-size: clamp(0.7em, 3cqi, 0.95em);
}

The buttons change the width of the example.

Visitors per month
Jan 41
Feb 38
Mar 52
Apr 61
May 74
Jun 88
Jul 93
Aug 90
Sep 77
Oct 63
Nov 49
Dec 45
HTML
<div class="text-box">
	<figure data-chart="column">
		<figcaption><b>Visitors per month</b></figcaption>
		<table>
			<tbody>
				<tr><th>Jan</th><td>41</td></tr>
				<tr><th>Feb</th><td>38</td></tr>
				<tr><th>Mar</th><td>52</td></tr>
				<tr><th>Apr</th><td>61</td></tr>
				<tr><th>May</th><td>74</td></tr>
				<tr><th>Jun</th><td>88</td></tr>
				<tr><th>Jul</th><td>93</td></tr>
				<tr><th>Aug</th><td>90</td></tr>
				<tr><th>Sep</th><td>77</td></tr>
				<tr><th>Oct</th><td>63</td></tr>
				<tr><th>Nov</th><td>49</td></tr>
				<tr><th>Dec</th><td>45</td></tr>
			</tbody>
		</table>
	</figure>
</div>

Much smaller than that, text gets hard to read. If a number still does not fit, the chart has to omit it. If you hover over its column, bar or point (or tap it on a touch device), the tooltip shows it.