<sub> Subscript

Subscript text, set below the line, as in H2O.

<sub> renders text as subscript, lower and smaller than the text around it. Use it when typography calls for it: chemical formulas like H2O, or variable indexes like x1.

Shrinking or lowering text for decoration is a CSS job. Complex math needs MathML (<math>).

The sub and sup section of the HTML Living Standard (opens in a new tab) restricts both elements to typographical conventions, never presentation. For exponents, its partner is the sup element.

Syntax

H<sub>2</sub>O

When to use it

Some writing conventions put characters below the line, and <sub> marks them: chemical formulas in a science article, the base of a number in a computing lesson (10102), or an index on a variable in a simple math note (x1, x2). In each case the lowered position carries meaning.

Its partner sup raises text instead. For real equations with fractions, roots or matrices, use MathML, where subscripts are built with <msub> and keep their structure for assistive technology. For a lowered piece of a logo or a decorative layout, use CSS vertical-align.

You may be tempted to type Unicode subscript digits instead of using sub. They exist only for a small set of characters, not every font draws them, and many search tools treat them as different characters from normal digits. The sub element works with any text and keeps the plain characters underneath, so search and copy behave normally.

Live example

Edit the code and watch the preview.

<p>Water is H<sub>2</sub>O and carbon dioxide is CO<sub>2</sub>.</p>

More examples

Chemical equation

A balanced equation uses sub for the number of atoms in each molecule. The arrow is written as an HTML entity, and normal-sized numbers in front of a formula show how many molecules there are.

<p>Burning hydrogen:</p>
<p>2H<sub>2</sub> + O<sub>2</sub> &rarr; 2H<sub>2</sub>O</p>

Number bases

In a computing lesson, a subscript shows which number system a value is written in. The same quantity looks very different in base 2, base 10 and base 16. Without the subscripts, 10 could mean ten or two.

<p>1010<sub>2</sub> = 10<sub>10</sub> = A<sub>16</sub></p>
<p>11111111<sub>2</sub> = 255<sub>10</sub> = FF<sub>16</sub></p>

Tip: Real typographic subscripts only.

Browser support

sub has been in HTML since HTML 3.2 and works in every browser. The default style is vertical-align:sub with a smaller font size, which can slightly increase the line height; many stylesheets adjust this with line-height or relative positioning.

Accessibility

Screen readers usually read subscripts as plain digits, so H2O can come out as H 2 O. For formulas that count, add a short explanation in text. MathML Core (opens in a new tab) gives screen readers real math structure for anything complex.

Common mistakes

Wrong

<sub>Terms apply</sub>

Right

<small>Terms apply</small>

sub is for typographic subscripts like formulas. Shrink text with CSS.

Frequently asked questions

How do I write H2O in HTML?

Put the number in <sub>: H<sub>2</sub>O. The element is for typographical conventions that need subscript, such as chemical formulas and variable indexes like x<sub>1</sub>. It is not a text shrinker. Complex mathematics with fractions or roots belongs in <math> (MathML), which screen readers can interpret. More typical uses are listed in Wikipedia's article on subscripts and superscripts (opens in a new tab).

Why does sub change my line height?

Browsers lower <sub> with vertical-align:sub, and that can push the line box taller and leave uneven gaps between lines. One common fix is sub{line-height:0}. Another is vertical-align:baseline;position:relative;top:.25em, which positions the subscript without touching the line spacing. Check the result on a few lines of wrapped text.

Related text elements

<p>One paragraph of text.<br>Breaks the line inside text, as in a postal address or a poem.<hr>A change of topic between paragraphs, drawn as a horizontal line.<pre>Shows text exactly as typed, spaces and line breaks included.<blockquote>A longer quotation from another source, set apart as its own block.<div>A generic block box with no meaning, for grouping and styling.<span>A generic inline wrapper with no meaning, for styling part of a line of text.<strong>Text that is important, serious or urgent. Shown in bold by default.<em>Stress emphasis that changes what a sentence means. Italic by default.<b>Makes text stand out without adding importance, as with keywords. Bold by default.<i>Text in another voice: foreign words, terms, thoughts, ship names. Italic.<u>Text with an unspoken annotation, such as a flagged spelling error.<s>Content that is no longer accurate or relevant, drawn crossed out.<mark>Highlighted text, like a marker pen, showing relevance in the current context.<small>Side comments and fine print, like copyright lines or legal notes.<sup>Superscript text, set above the line, as in exponents or 1st.<code>A fragment of computer code, set in a monospace font.<kbd>Keys or text the user should press or type.<samp>Sample output from a program or a computer system.<var>A variable in math or in code. Italic by default.<q>A short quotation inside a sentence. The browser adds the quote marks.<cite>The title of a creative work: a book, film, song, game or article.<abbr>An abbreviation or acronym, with an optional expansion in title.<dfn>Marks the term that the surrounding sentence or paragraph defines.<time>Marks a date, time or duration and gives it a machine-readable value.<data>Ties visible content to a machine-readable value.<del>Text that was removed from the document. Struck through by default.<ins>Text that was added to the document. Underlined by default.<wbr>A spot where the browser may break a long word if it has to.<bdi>Isolates text of unknown direction, such as user names.<bdo>Forces a text direction and overrides the normal bidi algorithm.<ruby>Small annotations above or beside text, mostly for East Asian pronunciation.<rt>The small reading or note in a ruby annotation.<rp>Fallback brackets around ruby text, shown only where ruby is unsupported.