- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <sub> Tag
HTML Tags
HTML <sub> Tag
The sub tag lowers text below the line and makes it smaller: the 2 in H₂O, the index in xᵢ. Use it when the lowered position is part of the meaning, as in chemical formulas.
Its partner, the sup tag, raises text instead, for powers and footnote numbers.
Syntax
html
<sub>Subscript text</sub>There are no special attributes, only the global ones such as class, id, style and title.
Example
html
<!DOCTYPE html>
<html>
<head>
<title>SUB Tag Example</title>
<style>
.chemical {
color: #2c3e50;
font-size: 0.9em;
}
</style>
</head>
<body>
<h1>HTML <sub> Tag Example</h1>
<p>
Water chemical formula: H<sub class="chemical" id="water-sub" title="Subscript">2</sub>O
</p>
<p>
Example: CO<sub>2</sub> is carbon dioxide.
</p>
</body>
</html>Both formulas show their numbers lowered: H₂O for water and CO₂ for carbon dioxide.
Keep line spacing even
A <sub> can push its line a little further from the next one, making paragraphs look uneven. This fix keeps lines the same height:
Subscript without uneven lines
css
sub {
line-height: 0;
vertical-align: sub;
font-size: 0.75em;
}Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
Good to know
- Use
<sub>for meaning, not for looks. To lower text just for design, use CSSvertical-align. - For real mathematics, MathML (
<math>) handles subscripts, fractions and roots far better. - Screen readers usually read
H<sub>2</sub>Oas "H 2 O", which is fine for formulas.
HTML <sub> Tag exercises
Write a chemical formula
Write H2O in a paragraph, with the 2 as a subscript.
Result
Check your answer to see it here.
