Description
The HTML element <sub>
is used to define a subscript text.
The subscript text appears half a character's height below the baseline, which is usually used in mathematical and chemical formulas.
- This element should not be used for typographical reasons, meaning just to align or display the content.
- This element should not be used for changing the vertical alignment of a text. Instead, use the CSS property
vertical-align: sub;
to apply the vertical alignment style.
The below table summarizes its usage.
Usage Details | |
Placement | It is displayed as an Inline element. |
Contents | It can contain Inline elements and text. |
Tags | Both the opening and closing tags are required. |
Versions | HTML 3.2, 4, 4.01, 5 |
Syntax
Here is the basic syntax of the <sub>
element.
<sub>...</sub>
Examples
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example - HTML Element sub</title>
</head>
<body>
<p>The chemical formula of water is: H<sub>2</sub>O</p>
<p>Sample mathematical formula is: y = log<sub>a</sub>x</p>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <sub>
element.
Attribute Type | Details |
Element-Specific Attributes | The tag <sub> doesn't have any element-specific attributes. |
Global Attributes | Like all other HTML tags, the tag <sub> supports the HTML Global Attributes. |
Event Attributes | The tag <sub> also supports the HTML Event Attributes. |
Browser Compatibility
The tag <sub>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 3+
- Firefox 1+
- Apple Safari 1+
- Opera 4+