Here is a helpful snippet for formatting text using CSS:
td {
vertical-align:baseline;
}
sel {
vertical-align:sub;
}
<table>
<tr>
<td>test</td>
<td>foo<sel>c</sel></td>
<td>bar</td>
</tr>
</table>
Extracted from the official CSS specification:
Adjust the baseline of the container to fit subscripts of its parent container.
https://www.w3.org/TR/CSS2/visudet.html#propdef-vertical-align
Explanation (Reasoning behind this behavior):
The <tbody>
element utilizes vertical-align:middle;
, which vertically centers the entire content within it. This styling cascades down to the <td>
elements as well. Consequently, with subscript included, the content appears slightly higher compared to when it's absent. As a result of this centering effect, there may be an imbalance where the subscript causes the text height to extend. To maintain the letters on a single line, setting the vertical-align
property to baseline is necessary. The baseline functions as the reference line where the letters align. By applying this to all items in a row, the text (excluding subscripts) should remain on one consistent line.