How to Align Numbers in CSS Tables with tabular-nums
To line up the digits of a table vertically, set every digit to the same width with the CSS font-variant-numeric: tabular-nums, and right-align the numeric columns with text-align: right. When both are in place, the ones place, the tens place, and the commas line up in the same position on every row.
The test environment was Ubuntu 24.04, Node.js 22.23.4, Playwright 1.63.0, and Chromium 153. I used the fonts Inter 4.0, Noto Sans CJK JP, and DejaVu Sans, opened a test page with Playwright, and measured the position and width of each character. I did not test Firefox or Safari, or how the tables look with the fonts installed on Windows or macOS. The browser support versions come from the compatibility data (@mdn/browser-compat-data 8.1.8).

- 1. How to write it
- 2. If the digit widths differ, the digits drift even when right-aligned
- 3. Left-aligned cells do not line up even with equal widths
- 4. Decimals: align the number of digits after the decimal point
- 5. Some fonts already have equal digit widths
- 6. font-feature-settings gives the same result
- 7. Supported in major browsers
How to write it
Add the class num to the cells in the numeric columns, and set tabular-nums on the whole table.
<table>
<thead>
<tr><th>月</th><th class="num">売上(円)</th><th class="num">伸び率(%)</th></tr>
</thead>
<tbody>
<tr><td>4月</td><td class="num">111,111</td><td class="num">8.50</td></tr>
<tr><td>5月</td><td class="num">888,888</td><td class="num">12.25</td></tr>
<tr><td>6月</td><td class="num">47,210</td><td class="num">3.00</td></tr>
<tr><td>7月</td><td class="num">1,019</td><td class="num">10.75</td></tr>
</tbody>
</table>
table {
font-variant-numeric: tabular-nums;
}
.num {
text-align: right;
}
font-variant-numeric is inherited by child elements (CSS Fonts Level 4 specification). In the test environment, setting it on table made the values in the td elements use tabular-nums. You only need to write it once per table. If you also add num to the th headers, the column headers line up on the right side with the numbers, as in the image above.
If the digit widths differ, the digits drift even when right-aligned
Some Latin fonts give each digit a different width. In the test environment, I measured the width of each digit in Inter, and got the following results. The unit is em (a ratio to the font size).
| Digit | Default | tabular-nums |
|---|---|---|
| 0 | 0.631 | 0.648 |
| 1 | 0.407 | 0.648 |
| 4 | 0.646 | 0.648 |
| 7 | 0.566 | 0.648 |
| 8 | 0.619 | 0.648 |
Without the setting, "1" is about 0.24em narrower than "4". With tabular-nums, every digit from 0 to 9 measured 0.648em. MDN's description of font-variant-numeric says that tabular-nums displays digits at the same size (width) so they line up easily in tables, and that it corresponds to the OpenType tnum feature.
Right-aligning does not remove this difference in width. In the test environment, I right-aligned 111,111, 888,888, 47,210, and 1,019 in 20px Inter, and measured how far apart the right edges of the characters at the same position from the right (ones, tens, and so on) were across the rows.
| Character counted from the right | Default | tabular-nums |
|---|---|---|
| 1st (ones place) | 0.00px | 0.00px |
| 2nd (tens place) | 4.48px | 0.00px |
| 4th (comma) | 12.72px | 0.00px |
| 7th (hundred-thousands place) | 22.03px | 0.00px |
Because the text is right-aligned, the right edges of the ones place line up, but the drift grows toward the left digits. The whole string of 111,111, which uses only "1", was 52.84px wide, and 888,888, which uses only "8", was 79.11px wide, a difference of just over 26px. With tabular-nums, both were 83.19px wide, and the drift was 0 at every digit.
Left-aligned cells do not line up even with equal widths
Setting tabular-nums does not line up the digits if the cells are still left-aligned. The initial value of text-align for table cells (td) is start, which means left-aligned on pages written left to right.
In the test environment, I set only tabular-nums and placed 111,111, 47,210, and 1,019 in cells with no text-align value. The text-align value stayed start, and the right edges of the ones place were at 94.19px, 81.22px, and 68.25px. Each digit less moved the position 12.97px (one digit width) to the left. Even when the digit widths are equal, numbers with different digit counts only line up if their right edges are aligned.
Decimals: align the number of digits after the decimal point
In a column that contains decimals, right-alignment and tabular-nums alone do not line up the decimal points. In the test environment, I lined up 12.5, 3.25, 100, and 0.8. The left edge of the decimal point was at 36.94px for 12.5 and 0.8, and at 23.97px for 3.25. 100 has no decimal point.
If you make the number of digits after the decimal point the same before displaying, the decimal points line up on one vertical line. If you generate the values in JavaScript, set minimumFractionDigits and maximumFractionDigits of Intl.NumberFormat to the same value.
const format = new Intl.NumberFormat('ja-JP', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
});
['12.5', '3.25', '100', '0.8'].map((v) => format.format(Number(v)));
// → 12.50, 3.25, 100.00, 0.80
In the test environment, when I displayed these values as 12.50, 3.25, 100.00, and 0.80, the left edge of the decimal point was at 49.91px in all four rows.
The CSS Text Level 4 specification describes a way to align a column on a specified character, such as text-align: ".". However, in Chromium 153 in the test environment, CSS.supports('text-align', '"."') returned false, so I could not use it. The compatibility data for the text-align values does not include this syntax either.
Some fonts already have equal digit widths
With fonts whose digits are designed to have the same width from the start, setting tabular-nums does not change how they look. In the test environment, the digits in Noto Sans CJK JP are all 0.555em, and the digits in DejaVu Sans are all 0.636em. The width was the same with or without the setting.
Even if you later change the table's font to one with different digit widths, such as Inter, the digits stay aligned as long as the setting remains.
font-feature-settings gives the same result
Using font-feature-settings: "tnum", which turns on the font's tnum feature directly, gave the same width as tabular-nums (83.19px) in the test environment, and the drift was also 0.
However, MDN's description of font-feature-settings recommends using individual properties such as font-variant-numeric whenever possible. If you only need to equalize digit widths, use font-variant-numeric: tabular-nums.
Supported in major browsers
According to the compatibility data, tabular-nums for font-variant-numeric is supported in Chrome 52, Edge 79, Firefox 34, Safari 9.1, Safari on iOS 9.3, and Chrome on Android 52 and later.





