×

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

Related Topics

CSS Browser Support

The desk underneath lists of all CSS properties and the way each belongs to it is supported in the generally unique browsers: - The quantity to the right of the browser...

2 minutes read.

CSS Align

CSS Center Align Elements CSS center align is used to create align by using block element. You should specify margin: auto;properties. The element will take up the specified width and the remaining space....

2 minutes read.

How to center a table in CSS

The table is used to store and arrange the data in tabular format. The data here can be of any form like text, image, links, etc. The table is made...

3 minutes read.

CSS Selector

CSS Selector: There are some selectors used in CSS, which allows us to choose the content we wish to style. Various selectors are considered as the separation of the set...

5 minutes read.

CSS Introduction

CSS stands for Cascading Style Sheet. It is a design language which is used to design the web pages. It was developed by Håkon Wium Lie on October 10, 1994. It provides...

1 minute read.

CSS Page-break-after Attribute

Page-break-after Attribute As its name implies, the page-break-before property is applied to include page break after any element, at the time of printing a document. It adds the page break after...

5 minutes read.

CSS Radio Button

Radio Button A radio button has been defined as an element of HTML. It can support us to take any input from the user. But it is challenging to design a...

4 minutes read.

Divi in CSS

Divi is popular WordPress themes due to its versatility and user-friendly interface. It includes a built-in page builder for sophisticated design options and an assortment of customization features to help...

9 minutes read.

CSS Word-spacing

Word-spacing The work-spacing property of CSS is applied to manage the space among the words. We can decrease or increase the space among the words by the use of this property. It...

3 minutes read.

CSS Background Color

It is one of the CSS properties to apply styling to html elements.This property is used to apply the background color to any HTML element.The background of an element includes...

2 minutes read.

CSS Text-align

Text-align The text-align property of CSS sets the table-cell box’s horizontal alignment or any block element. The text-align property is the same as the CSS property vertical-align but towards any horizontal...

1 minute read.

CSS Dropdowns

Dropdowns are one of the maximum crucial parts of an interactive internet site. CSS is a kind used to design the drop-down menus. A drop-down essentially is a group of...

5 minutes read.

Css Box Model

Introduction The Box Model property of CSS is used for design and layout of an html page. In CSS, all the elements has a rectangular box around it, you have to...

5 minutes read.

CSS Flex-Box

Introduction The flex-box property of CSS stands for Flexible Box Layout Module. It is specifically used to design a flexible responsive layout. Flex-box is a one dimensional layout model, i.e. it works...

6 minutes read.

CSS Inline

What is CSS? CSS is an acronym for Cascading Style Sheets. CSS is the language that we use to style an HTML document. It specifies how HTML components should appear. CSS...

4 minutes read.

CSS Justify Content

Justify Content: These properties are applied for the alignment of items of a flexible box container if any item does not cover every available space over the main-axis, i.e., horizontally....

4 minutes read.

CSS User Interface

Introduction User Interface can be defined as series of visual elements like screens, buttons, forms that help the user interact with the software application or hardware device. CSS User Interface allows the...

6 minutes read.

CSS Outline

CSS Outline: This CSS property is quite similar to the border property of CSS. It eases us to design an additional border around the element to obtain visual attention. The...

4 minutes read.

CSS Important

CSS Important: CSS !important property is used to provide more importance, as compared to other CSS properties. The meaning of this property is “This is important.” This property enables CSS...

2 minutes read.

CSS Page-break-inside Attribute

Page-break-inside Attribute As its name implies, the page-break-before property is applied to include page break inside any element, at the time of printing any document. It adds the page break before...

3 minutes read.