htmlweb

How to format a superscript with HTML


The text Kasparov and 1 written somewhat above to it

How do I format this in a HTML page? What is the tag for it? I don’t know how to get this 1 written above the text.


Solution

  • Probably the <sup> element for superscript text.

    Likethis.

    <p>Like<sup>this</sup></p>
    

    There's also <sub> for subscript text:

    Likethis.

    <p>Like<sub>this</sub></p>
    

    Note that these elements are meant for actual textual superscript and subscript text. Remember that HTML is semantic: it describes what the content is, not what the content looks like (that's what CSS is for).

    In CSS you can do this the simple way by setting vertical-align: super with font-size: 80% on an inline-element (like <span> but not <div>, a block-element).

    Another approach is to do it manually with creative use of margin or position: relative - in which case it depends on your application.