HTML <sub>
Tag
Introduction
The <sub>
tag in HTML is used to define subscript text. Subscript text appears slightly below the normal line of text and is commonly used for footnotes, mathematical expressions, chemical formulas, and more. In this tutorial, we will explore how to use the <sub>
tag effectively in your HTML documents.
Usage
To use the <sub>
tag, simply place the text you want to be subscripted within the opening and closing tags. For example:
<p>H<sub>2</sub>O is the chemical formula for water.</p>
This will produce the following output: H2O is the chemical formula for water.
Attributes
The <sub>
tag does not have any specific attributes of its own, as it is a standalone tag. However, it inherits some of the global attributes of HTML, such as class
, id
, style
, and title
.
Main Tag Attributes
Attribute | Description |
---|---|
class | Defines a class name for the element, allowing you to apply CSS styles. |
id | Defines a unique id for the element, which can be used for JavaScript interactions. |
style | Defines inline CSS styles for the element. |
title | Defines a title for the element, usually displayed as a tooltip when the mouse hovers over it. |
For example, you can apply a specific class to the <sub>
tag to style it differently:
<sub class="important">Important Text</sub>
Conclusion
The <sub>
tag is a powerful tool in HTML for displaying subscript text. By using it appropriately and understanding its attributes, you can enhance the readability and visual appeal of your content. Experiment with different styling options and see how the <sub>
tag can elevate your HTML documents!