CSS Introduction

CSS Tutorial What is CSS CSS Syntax CSS Selector How to include CSS CSS Comments

CSS Attributes

CSS Background CSS Border CSS Display CSS Float CSS Font CSS Color CSS Hover CSS Important CSS Line-height CSS Margin CSS Opacity CSS Filter CSS Images CSS Overflow CSS Padding CSS Position CSS Vertical align CSS White space CSS Width Word-wrap in CSS Box-shadow in CSS Text-transform in CSS CSS Outline CSS Visibility CSS Counters CSS Clear fix CSS Icons CSS Justify-content Text-decoration in CSS CSS Lists CSS nth selector CSS Sticky CSS Background-clip CSS Checkbox-style CSS Letter-spacing CSS Navigation bar CSS Overlay CSS Root CSS Specificity CSS Text-indent CSS Text-stroke CSS Zoom CSS Order CSS Descendent selector CSS Clip CSS calc() CSS Background-blend-mode CSS radio-button CSS Superscript and subscript CSS Text-effects CSS Text-align CSS Variables CSS Page-break-before CSS Page-break-inside CSS Page-break-after CSS Content property CSS Word-spacing CSS Animation CSS @keyframes rules CSS Pseudo-classes CSS Pseudo-elements CSS Radial-gradient CSS Translate CSS Gradients CSS z-index CSS Loaders CSS Units CSS Transition CSS Masking CSS Arrow CSS Pagination

Misc

What is Bootstrap CSS What is CSS used for Difference between HTML and CSS How to center a table in CSS What is a CSS File How to center a button in CSS How to change background color in CSS How to change the font in CSS How to change font size in CSS How to resize an image in CSS How to get rid of bullet pioints in CSS Is CSS a programming language Grid Vs Flexbox in CSS How to edit CSS in WordPress How to use google fonts in CSS

CSS Superscript and Subscript

Superscript and Subscript

To specify the superscript and the subscript text, HTML provides us two tags that are <sup> and <sub>. The superscript content looks in the shorter font and half character over the regular line. Generally, these tags are used to address the footnotes, mathematical equations (such as x2 + y2 = r2), and others.

The subscript content shows in the shorter font, unlike superscript and half character down the regular line. Generally, it can be used for addressing chemical formulas like H2SO4, H2O, and mathematical equations, etc.

The CSS vertical-align attribute is applied to accomplish a similar thing. Subscript and superscript can be specified with the use of CSS also. This CSS attribute describes the text’s vertical alignment.

Now, let’s understand how to accomplish the subscript and superscript with the use of a vertical-align attribute.

Syntax:

vertical-align: baseline | super | sub ;  

Values

Baseline: This value is a default value. It aligns the content to the parent element’s baseline.

Super: This value is superscript. It is used to raise any text.

Sub: This value is subscript. It is used to lower any text.

The content will become subscript and superscript when we apply the sub and super values of this attribute.

Superscript- Example:

<!DOCTYPE html>
<html>
<head>
<style>
#super
{
 vertical-align: super;
 font-size: medium;
}
p
{
 font-weight: bold;
 font-size: 20px;
}
</style>
</head>
<body>
<h1> vertical-align: super; </h1>
<p> Formulas, mathematical equations, and exponents are some basic uses of the superscript content. </p>
<h3>x<span id= "super">2</span>+y<span id= "super">2</span>=r<span id= "super">2</span></h3>
<h3>(a+b)<span id= "super">2</span>=a<span id= "super">2</span>+b<span id= "super">2</span>+2ab</h3>
<h3>5<span id= "super">th</span></h3>
</body>
</html>

Output:

CSS Superscript and Subscript

Subscript- Example:

<!DOCTYPE html>
<html>
<head>
<style>
#sub
{
 vertical-align: sub;
 font-size: medium;
}
p
{
 font-size: 20px;
}
</style>
</head>
<body>
<h1> vertical-align: sub; </h1>
<p> Chemical equation is one of its basic example. </p>
<h3> Ammonia's chemical formula is: NH<span id= "sub">3</span> </h3>
<h3> Ethanol's chemical formula is: C<span id= "sub">2</span>H<span id= "sub">5</span>O </h3>
</body>
</html>

Output:

CSS Superscript and Subscript



ADVERTISEMENT
ADVERTISEMENT