Creating a Subscript or Superscript with HTML
By Stephen Bucaro
A subscript is a number, letter, or symbol written directly next to and
slightly below a word or phrase that can be used to reference the word or phrase to
a footnote. A subscript is also used in chemistry to indicate the number of atoms
of an element in a molecule. To create a subscript, use the <sub></sub>
tag, as shown below.
The chemical formula for water is H2O, and the formula for Hydrogen Peroxide is H2O2.
<p>The chemical formula for water is H<sub>2</sub>O, and the formula
for Hydrogen Peroxide is H<sub>2</sub>O<sub>2</sub>.</p>
If you want to use a subscript reference a footnote, note that the <sub>
tag responds to the onclick event. This means, you can use Java Script with
the document's location object, to set it up so the user can click on the
subscript and be taken to the footnote, as shown below.
Click on the number1 to be taken to the footnote
Example code for a footnote is shown below.
<p><a name="footnote1"><sup>1</sup></a> This is the footnote text</p>
A superscript is a number, letter, or symbol written directly next to and
slightly above a a number, letter, or symbol. A superscript is frequently used in
mathematics to indicate and exponent. To create a superscript, use the
<sup></sup> tag, as shown below.
Mass and energy are related as defined by Einstein's formula E=mC2,
where energy (E) is equal to the mass (m) multiplied by the speed of light (C) squared.
<p>Mass and energy are related as defined by Einstein's formula E=mC<sup>2</sup>,
where energy (E) is equal to the mass (m) multiplied by the speed of light (C) squared.</p>
Many webmaster's today prefer to use CSS as much as possible to replace html.
In that case, you can replace the <sub> or <sup> with the <span>
tag and then use the vertical-align style property to set the verticle
position of the subscript or superscript, as shown below.
The chemical formula for water is H2O
<p>The chemical formula for water is H<span style="vertical-align:-0.5em">2</span>O</p>
Einstein's formula is E=mC2
<p>Einstein's formula is E=mC<span style="vertical-align:0.4em">2</span></p>
The above examples use in-line style to offset the subscript or superscript vertically by 0.5em.
An em unit is equal to the height of the capital letter "M" in the currently defined font size.
1 This is the footnote text
More HTML Code:
• Easy Form Design
• HTML5 Slider Control
• Line Breaks in HTML
• HTML title Tag
• HTML5 Input Type - Email
• HTML Horizontal Rule
• Use fieldset to Organize Form Elements
• The Heading Tags
• HTML Text Tags Basics
• Divide a Table Into Head (thead), Body (tbody), and Footer (tfoot) Sections