Open In App

HTML <sub> Tag

Last Updated : 21 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The <sub> tag in HTML is used to define subscript text, which appears smaller and slightly below the normal text baseline. It is commonly used for mathematical expressions, chemical formulas, and footnotes, like in H₂O (water) or E=mc² (Einstein’s equation).

Syntax

<sub> Contents. . . </sub>

There are no such attributes that apply specifically to this <sub> tag. The attributes that only apply to this tag are global attributes.

Example 1: In this example, the <sub> tag is used to create subscript text. The "2" in the chemical formula "H₂O" is displayed as smaller and slightly lower than the baseline, indicating the number of hydrogen atoms.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>HTML sub tag</title>
</head>

<body style="text-align: center;">

    <h1 style="color: green;">
        GeeksforGeeks
    </h1>

    <h2>Chemical Formula of Water</h2>

    <h2>H<sub>2</sub>O</h2>
</body>

</html>

Output:

Example 2: In this example the <sub> tag is used to display subscript text. It renders the "n" in the mathematical expression "xₙ + yₙ" smaller and below the baseline, indicating a variable's subscript.

HTML
<!DOCTYPE html>
<html>

<head>
    <table>
        HTML sub tag
    </table>
</head>

<body style="text-align: center;">

    <h1 style="color: green;">
        GeeksforGeeks
    </h1>

    <h2>Mathematical Formula</h2>

    <h2>x<sub>n</sub> + y<sub>n</sub></h2>
</body>

</html>

Output:

Supported Browsers:


Next Article

Similar Reads

  翻译: