Unicode superscripts and subscripts
There are alternatives to using <sup> and <sub> tags for superscripts and subscripts in HTML. These alternatives may look better, depending on context, and they can be used in plain (Unicode) text files where HTML markup isn't available.
SuperscriptsWhen I started blogging I would use <sup>2</sup> and <sup>3</sup> for squares and cubes. Then somewhere along the way someone told me about ² (U+00B2) and ³ (U+00B3) and I started using these. The superscript characters generally produce slightly smaller subscripts and look nicer in my opinion.
Example with sup tags:
a2 + b2 = c2
Example with superscript characters:
a^2 + b^2 = c^2
But there are no characters for exponents larger than 3. Or so I thought until recently.
There are no HTML entities for exponents larger than 3, nothing written in notation analogous to ² and ³. There are Unicode characters for other superscripts up to 9, but they don't have corresponding HTML entities.
The Unicode code point for superscript n is
2070hex + n
except for n = 2 or 3. For example, U+2075 is a superscript 5. So you could write x as
<em>x</em>⁵.
SubscriptsThere are also Unicode symbols for subscripts, though they don't have corresponding HTML entities. The Unicode code point for superscript n = 0, 1, 2, ... 9 is
2080hex + n
For example, U+2087 is a subscript 7.
The subscript characters don't extend below the baseline as far as subscripts in <sub> tags do. Here are xs with subsubcripts in <sub> tags.
x0, x1, x2, x3, x4, x5, x6, x7, x8, x9
And here are the single character subscripts.
x, x, x, x, x, x, x, x, x, x
I think the former looks better, but subscripts in HTML paragraphs may increase the vertical spacing between lines. If consistent line spacing is more important than conventional subscripts, you might prefer the subscript characters.
Related postsThe post Unicode superscripts and subscripts first appeared on John D. Cook.