HTML <sub> Tag โ Subscript Text
๐ Introduction
The <sub> tag is used to display subscript text in HTML.
Subscript text appears smaller and slightly below the normal line of text.
It is commonly used in:
- Chemistry formulas
- Mathematical expressions
- Scientific notation
๐งฑ Syntax
<sub>text</sub>
๐ก Example
<!DOCTYPE html>
<html>
<head>
<title>Sub Tag Example</title>
</head>
<body>
<p>Water chemical formula: H<sub>2</sub>O</p>
<p>Carbon dioxide: CO<sub>2</sub></p>
</body>
</html>
๐ฅ๏ธ Output Explanation
- The number inside
<sub>appears lower than normal text - It is smaller in size
- Used to represent scientific notation correctly
๐ฏ When to Use <sub>
Use <sub> for:
- Chemical formulas
- Mathematical expressions
- Footnote references (sometimes)
Example:
<p>E = mc<sub>2</sub></p>
โ๏ธ <sub> vs <sup>
| Tag | Position | Use |
|---|---|---|
<sub> |
Below text | Chemistry, formulas |
<sup> |
Above text | Powers, exponents |
Example:
<p>H<sub>2</sub> + O<sub>2</sub></p>
<p>x<sup>2</sup> + y<sup>2</sup></p>
๐ซ Common Mistakes
- Using
<sub>for normal text formatting โ - Using it for layout positioning โ
- Confusing it with CSS positioning โ
๐จ Styling <sub>
You can customize it:
<sub style="color: red;">2</sub>
๐งช Mini Exercise
Create a page with:
Chemical formulas:
- HโO
- COโ
At least one mathematical expression using
<sub>