👀 Live Preview
Water formula with subscript hydrogen count:
H2O

The <sub> tag renders subscript text below the baseline. This guide covers syntax, chemical formulas, mathematical indices, sub vs sup, accessibility, and best practices for beginners.
Text below the baseline.
H2O and compound notation.
Variable subscripts like A1.
Inline opening and closing tags.
Below vs above baseline.
Semantic, accessible markup.
<sub> Tag?The <sub> tag is an HTML element used to render text in a subscript style. Subscripted text appears slightly below the baseline and is commonly used for mathematical indices, chemical formulas, and variable notation.
Use sub when characters genuinely belong below the line, such as the 2 in H2O. For superscript (above the line), use <sup> instead.
The sub element is inline and flows naturally inside paragraphs, headings, and other text content without breaking the line.
Enclose the subscript content within opening and closing sub tags:
<sub>Your subscripted text here</sub><p>This is a chemical formula: H<sub>2</sub>O</p>sub is phrasing content — use inline inside block elements like p or td.<sub />) is not valid in HTML.| Topic | Code Snippet | Notes |
|---|---|---|
| Basic sub | <sub>...</sub> | Subscript |
| Water formula | H<sub>2</sub>O | Chemistry |
| Math index | A<sub>1</sub> | Variables |
| vs sup | sub = below | sup = above |
| Footnote refs | Prefer sup | Common convention |
| Browser support | Universal | All browsers |
<sub> vs <sup>| Element | Position | Common uses |
|---|---|---|
<sub> | Below baseline (subscript) | H2O, A1, CO2 |
<sup> | Above baseline (superscript) | x2, footnote markers[1] |
| Appearance | Both smaller than surrounding text | Browser default typography |
| Footnotes | sup is standard | sub for true subscript only |
The <sub> tag has no tag-specific attributes. Combine it with global attributes for styling when needed.
<p>This is a chemical formula: H<sub>2</sub>O</p>class / id GlobalHook for CSS targeting subscript styling in formulas or notation.
class="subscript"style GlobalInline font-size or vertical-align tweaks (rarely needed).
style="font-size: 0.75em"title OptionalTooltip explaining a subscript symbol or abbreviation.
title="Index 1"lang OptionalDeclare language when subscript text differs from the page.
lang="en"Chemical formulas, mathematical indices, and reference markers with copy-ready code and live previews.
Water formula with subscript hydrogen count:
H2O
Use <sub> for chemical formulas, mathematical indices, and any text that belongs below the baseline.
Represent subscript numbers in chemical compounds such as water:
<p>This is a chemical formula: H<sub>2</sub>O</p>The sub tag is commonly used in mathematical expressions to represent indices or subscripts:
<p>
The area (A<sub>1</sub>) of the first circle is smaller than the area (A<sub>2</sub>) of the second circle.
</p>Subscript can mark reference indices in technical prose. For typical footnote numbers, sup is the more common choice:
<p>This statement requires clarification<sub>1</sub>.</p>sup, not sub.Characters that belong below the baseline go inside sub.
Default styles render text smaller and below the baseline.
H2O and A1 display with proper scientific notation.
Scientific and mathematical content is visually accurate and semantically correct.
The <sub> tag is supported in all major browsers, including Internet Explorer.
All browsers render <sub> with subscript typography by default.
Bottom line: Use <sub> confidently for subscript text in any browser.
Mastering the <sub> tag helps you present subscripted text with precision. Whether writing chemical formulas or mathematical indices, sub enhances visual clarity and semantic accuracy in your HTML documents.
sub for genuine subscript content like H2Osup for superscript and footnote markerssub for decorative positioning without meaningsubsub when sup is the correct notation<sub>Bookmark these before you write subscript text on your pages.
Below baseline.
PurposeChemistry.
Use caseMath indices.
PatternAbove vs below.
ComparisonMeaningful use.
A11yAll browsers.
Compatibilitysub places text below the baseline. sup places text above it, such as exponents or footnote markers.class, id, and style.Practice <sub> for chemistry, math, and scientific notation in the Try It editor.
6 people found this page helpful