HTML - <sub> Tag



Introduction to <sub> Tag

The HTML <sub> tag is used to define the subscript text. The subscript text appears smaller and slightly below the baseline of the regular text. It is used in mathematical formulas, chemical equations. For example, the chemical formula for water is written as H2O.

The <sub> tag is a inline-level, that does not break the flow of text and can be used within the paragraphs, headings or other inline elements.

Syntax

Following is the syntax of HTML <sub> tag −

<sub>.....</sub>

Attributes

HTML sub tag supports Global and Event attributes of HTML.

Example : Chemical Formula

Let's look at the following example, where we are going to use the <sub> tag and writting the chemical formula.

<!DOCTYPE html>
<html>
<body>
   <h1>The sub tag</h1>
   <p> 
      Almost every developer's favorite molecule is C 
      <sub>8</sub>H <sub>10</sub>N <sub>4</sub>O <sub>2</sub>, 
      which is commonly known as "caffeine." </p>
</body>
</html>

Example : Mathematical Notation

Consider the following example, where we are going to use the <sub> tag to represent mathematical notation.

<!DOCTYPE html>
<html>
    <style>
        body{
            text-align:center;
            font-family:verdana;
            color:green;
        }
    </style>
<body>
<p>The mathematical notation of log1 base 2 is represented as log1<sub>2</sub>.</p>
</body>
</html>

Supported Browsers

Tag Chrome Edge Firefox Safari Opera
sub Yes Yes Yes Yes Yes
html_tags_reference.htm
Advertisements