The <sup> tag is used to define a superscript text, which appears half a character above the regular line and is rendered smaller than the rest of the text. The tag is commonly used to define footnotes and formulas.
You must use the <sup> tag only for typographical reasons. It shouldn’t be used for styling purposes. If you want to change the vertical position of a text, you can use the CSS vertical-align property with the "super" value.
Here are some use cases for a <sup> element:
- Representing superior lettering used in some languages when rendering specific abbreviations.
- Representing exponents (e.g. "x2.").
- Representing ordinal numbers (e.g. "5th" instead of "fifth").
Syntax
The <sup> tag comes in pairs. The content is written between the opening (<sup>) and closing (</sup>) tags.
Example of the HTML <sup> tag:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<p>
E = mc<sup>2</sup>, where E is the energy of the object, m is the weight, c is the light speed in vacuum.
</p>
</body>
</html>
Result
Example of the HTML <sup> tag used with the CSS vertical-align property:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
sup {
vertical-align: sup;
font-size: medium;
}
</style>
</head>
<body>
<h1>Example of the sub tag</h1>
<p>
Here is some text <sup> with the sup tag</sup>.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis ...
</p>
<p>
Reference site about Lorem Ipsum,
<sup> giving information on its origins</sup>, as well as a random Lipsum generator.
</p>
</body>
</html>
Example of the HTML <sup> tag used with the <sub> tag:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
sup {
vertical-align: sup;
font-size: medium;
}
sub {
vertical-align: sub;
font-size: small;
}
</style>
</head>
<body>
<h1>Example of the sub tag</h1>
<p>
Here is some text
<sub> with the sup tag</sub>.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis ...
</p>
<p>
Reference site about Lorem Ipsum,
<sup> giving information on its origins</sup>, as well as a random Lipsum generator.</p>
</body>
</html>
Attributes
The <sup> tag supports Global attributes and the Event Attributes.
How to style <sup> tag?
Common properties to alter the visual weight/emphasis/size of text in <sup> tag:
- CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit.
- CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element.
- CSS font-size property sets the size of the font.
- CSS font-weight property defines whether the font should be bold or thick.
- CSS text-transform property controls text case and capitalization.
- CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style.
Coloring text in <sup> tag:
- CSS color property describes the color of the text content and text decorations.
- CSS background-color property sets the background color of an element.
Text layout styles for <sup> tag:
- CSS text-indent property specifies the indentation of the first line in a text block.
- CSS text-overflow property specifies how overflowed content that is not displayed should be signalled to the user.
- CSS white-space property specifies how white-space inside an element is handled.
- CSS word-break property specifies where the lines should be broken.
Other properties worth looking at for <sup> tag:
- CSS text-shadow property adds shadow to text.
- CSS text-align-last property sets the alignment of the last line of the text.
- CSS line-height property specifies the height of a line.
- CSS letter-spacing property defines the spaces between letters/characters in a text.
- CSS word-spacing property sets the spacing between words.
Browser support
✓ | ✓ | ✓ | ✓ | ✓ |
Practice Your Knowledge
Quiz Time: Test Your Skills!
Ready to challenge what you've learned? Dive into our interactive quizzes for a deeper understanding and a fun way to reinforce your knowledge.