Sub and sup
Write subscripts and superscripts with <sub> and <sup>.
sub: subscript
The <sub> tag writes a subscript. It is used in chemistry formulas, index notation and footnote numbers. The browser shifts the content slightly down and shows it smaller.
Examples: water with <sub>2</sub> reads H<sub>2</sub>O; the first element reads a<sub>1</sub>. This gives 'H₂O' and 'a₁', not ordinary numbers.
sup: superscript
The <sup> tag writes a superscript. It is used in exponents and footnote numbers. The browser shifts the content slightly up and shows it smaller.
Examples: x squared with <sup>2</sup> reads x<sup>2</sup>; the first footnote with <sup>1</sup> reads Note<sup>1</sup>. This gives 'x²' and 'Note¹', not ordinary numbers.
Exercise Write a subscript and a superscript
Add a <p> to body. The text is: first the letter H, then a <sub> tag with content 2, then the letter O; a space; then the letter x, then a <sup> tag with content 2.
Show example solution
<body>
<p>H<sub>2</sub>O x<sup>2</sup></p>
</body>
Test yourself
-
Which tag writes a subscript?
- <sub>
- <sup>
- <under>
- <bottom>
Show answer
<sub> — Correct. sub writes a subscript.
-
Complete the sup tag
<p>Area formula: A = πr<____>2</sup></p>Show answer
<p>Area formula: A = πr<sup>2</sup></p> -
Match each tag to its role
- <sub>
- Subscript
- <sup>
- Superscript
- <code>
- Code piece
- <em>
- Emphasis