Table of Contents
Introduction to Subscript and Superscript Text in HTML
Subscript and superscript text in HTML are used to display characters slightly below or above the normal line of text. This is commonly used in mathematical formulas, chemical equations, and footnotes. HTML provides specific tags and CSS methods to achieve these effects.
Using the <sub> Tag
The <sub>
tag is used to create subscript text. It displays the enclosed text slightly below the normal line and usually in a smaller font size.
<p>The chemical formula for water is H<sub>2</sub>O.</p>
Try it:
Using the <sup> Tag
The <sup>
tag is used to create superscript text. It displays the enclosed text slightly above the normal line and usually in a smaller font size.
<p>The area of a circle is πr<sup>2</sup>.</p>
Try it:
Creating Subscript and Superscript with CSS
You can also use CSS to create subscript and superscript effects using the vertical-align
property.
<p>E = mc<span style="vertical-align: super; font-size: smaller;">2</span></p>
Try it:
Using Inline Styles
While generally not recommended for larger projects, you can use inline styles to create subscript and superscript effects.
<p>The first element of the periodic table is H<span style="vertical-align: sub; font-size: smaller;">1</span>.</p>
Try it:
Semantic Usage
When using subscript and superscript, consider the semantic meaning. Use <sub>
and <sup>
tags for proper semantic markup.
<p>The isotope of carbon used in radiocarbon dating is <sup>14</sup>C.</p>
<p>The chemical formula for sulfuric acid is H<sub>2</sub>SO<sub>4</sub>.</p>
Accessibility Considerations for Subscript and Superscript
When using subscript and superscript, ensure that the meaning is clear from context. Screen readers may not always convey the visual positioning of the text.
Best Practices
- Use
<sub>
and<sup>
tags for semantic markup - Use CSS for purely stylistic subscript and superscript effects
- Ensure the text is still readable when using subscript and superscript
- Consider providing additional context for screen readers if necessary
- Use subscript and superscript sparingly to maintain readability
Facing issues? Have Questions? Post them here! I am happy to answer!
- Stying HTML Tags with Hand-On Examples
- Remove Html head and body tags from ckeditor source
- What is the doctype for HTML5?
- HTML Images - Attributes and Formats
- Fibonacci series from 1 to 500 table
- HTML5 CSS3 Color Codes List
- Introduction to the HTML Paragraph
Tag
- How to set background color in HTML page?
- reCaptcha Verification expired. Check the checkbox again
- How to pretty print HTML using Java Code
- Comprehensive 256 Ascii code table with Html Hex IBM Microsoft Key
- Create HTML button that looks like a href hyperlink
- 9 Border to DIV Element in HTML Examples
- How to turn off autocomplete in input fields in HTML Form
- HTML5 HELLO WORLD Example
- How to word wrap in HTML
- Simple Crossword Puzzle example using Pure HTML, CSS and JavaScript
- Collection of Animated HTML Links (Anchor Tags) with CSS Code
- Chessboard with pieces using pure HTML and CSS
- Align html element at the center of page vertically and horizontally
- remove div vertical scroll
- Obsolete marquee element alternatives html5
- All directional arrows codes for HTML
- 70+ HTTP Error Codes CheatSheet
- W3 HTML validator warning Unable to Determine Parse Mode
- How to pass authorization header using cURL - cURL
- Ubuntu Linux: Unzip a zip file using Terminal - Ubuntu
- Read Text file from SD Card : Android Programming - Android
- Code2care Daily: Your Source for Tech & Programming News - April 14th, 2023 - News
- ActivityManager Warning: Activity not started, its current task has been brought to the front - Android
- JSP Hello World Program Tutorial with Eclipse and Tomcat Server - Java
- How to empty Trash in macOS? - MacOS
- [Solution] Exception in thread main java.util.EmptyStackException - Java