<sub> HTML element is used to represent subscript text within a line of text. It is commonly used to display mathematical formulas, chemical formulas, footnotes, or any content that needs to be placed below the normal text baseline.
Here’s an example of how to use the
<p>The chemical formula for water is H<sub>2</sub>O.</p>
In this example, the number “2” is wrapped within the
<sub> element. When rendered, the subscript text will appear slightly smaller and positioned below the baseline of the surrounding text, indicating that it represents the number of hydrogen atoms in the water molecule.
<sub> element can also be used for other purposes, such as displaying footnotes:
<p>This is an example sentence.<sup>[<sub>1</sub>]</sup></p>
In this case, the
<sub> element is used within the
<sup> element to create a superscript footnote marker, typically indicating that a corresponding footnote exists at the bottom of the page.
It’s important to note that the
<sub> element is primarily used for styling purposes and does not convey any specific semantic meaning. If you require semantic meaning, it is recommended to use more appropriate elements, such as
<sup> for superscript text or
<figcaption> for detailed explanations or descriptions.
In summary, the
<sub> element is used to represent subscript text within a line of text. It is typically used for mathematical formulas, chemical formulas, footnotes, or any content that needs to be placed below the normal text baseline. By using the
<sub> element, you can visually distinguish and indicate the position of subscript text within your content.