<sub>: The Subscript element #
::: section-content
The <sub>
HTML element specifies inline text which should
be displayed as subscript for solely typographical reasons. Subscripts
are typically rendered with a lowered baseline using smaller text.
:::
Try it #
::: section-content ::: iframe ::: {.output-header .border-rounded-top}
HTML Demo: <sub> #
Reset :::
::: {#warning-no-script .warning-container} ::: warning The interactive example cannot be shown because JavaScript is disabled. ::: :::
::: {#warning-mathml-not-supported .warning-container .hidden} ::: warning The interactive example cannot be shown because MathML is not supported by your browser. ::: :::
::: {#editor-container .editor-container .tabbed-shorter .hidden .border-rounded-bottom editor-type=“tabbed”} ::: {#tab-container .section .tabs} ::: {#tablist .tab-list role=“tablist”} HTML
CSS
JavaScript :::
::: {#html-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“html” aria-hidden=“true”} ::: {#html-editor}
Almost every developer’s favorite molecule is C8H10N4O2, also known as “caffeine.”
::: :::::: {#css-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“css” aria-hidden=“true”} ::: {#css-editor} p { font: 1rem ‘Fira Sans’, sans-serif; } ::: :::
::: {#js-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“js” aria-hidden=“true”} ::: {#js-editor} ::: ::: :::
::: {#output .output-container}
Output #
::: :::
::: {.section .console-container .hidden aria-hidden=“true”}
Console Output #
![] clear console
::: {#console .console} ::: :::
::: {#html-output .output .editor-tabbed} %html-content% ::: ::: :::
Attributes #
::: section-content This element only includes the global attributes. :::
Usage notes #
::: section-content
The <sub>
element should be used only for typographical reasons—that
is, to change the position of the text to comply with typographical
conventions or standards, rather than solely for presentation or
appearance purposes.
For example, using <sub>
to style the name of a company which uses
altered baselines in their
wordmark{target="_blank"}
would not be appropriate; instead, CSS should be used. For example, you
could use the
vertical-align
property with a declaration like vertical-align: sub
or, to more
precisely control the baseline shift, vertical-align: -25%
.
Appropriate use cases for <sub>
include (but aren't necessarily
limited to):
- Marking up footnote numbers. See Footnote numbers for an example.
- Marking up the subscript in mathematical variable numbers (although you may also consider using a MathML formula for this). See Variable subscripts.
- Denoting the number of atoms of a given element within a chemical formula (such as every developer's best friend, C ~8~ H ~10~ N ~4~ O ~2~ , otherwise known as "caffeine"). See Chemical formulas. :::
Examples #
Footnote numbers #
::: section-content
Traditional footnotes are denoted using numbers which are rendered in
subscript. This is a common use case for <sub>
:
::: code-example [html]{.language-name}
<p>
According to the computations by Nakamura, Johnson, and Mason<sub>1</sub> this
will result in the complete annihilation of both particles.
</p>
:::
Result #
::: {#sect1 .code-example} ::: iframe ::: ::: :::
Variable subscripts #
::: section-content In mathematics, families of variables related to the same concept (such as distances along the same axis) are represented using the same variable name with a subscript following. For example:
::: code-example [html]{.language-name}
<p>
The horizontal coordinates' positions along the X-axis are represented as
<var>x<sub>1</sub></var> … <var>x<sub>n</sub></var>.
</p>
:::
Result #
::: {#sect2 .code-example} ::: iframe ::: ::: :::
Chemical formulas #
::: section-content When writing a chemical formula, such as H~2~0, the number of atoms of a given element within the described molecule is represented using a subscripted number; in the case of water, the subscripted "2" indicates that there are two atoms of hydrogen in the molecule.
Another example:
::: code-example [html]{.language-name}
<p>
Almost every developer's favorite molecule is
C<sub>8</sub>H<sub>10</sub>N<sub>4</sub>O<sub>2</sub>, which is commonly known
as "caffeine."
</p>
:::
Result #
::: {#sect3 .code-example} ::: iframe ::: ::: :::
Technical summary #
::: section-content
Content categories | Flow content, phrasing content, palpable content. |
---|---|
Permitted content | Phrasing content. |
Tag omission | None, both the starting and ending tag are mandatory. |
Permitted parents | Any element that accepts phrasing content. |
Implicit ARIA role | subscript |
Permitted ARIA roles | Any |
DOM interface | HTMLElement |
Specifications #
::: _table #
Specification #
HTML Standard
[#
the-sub-and-sup-elements]{.small}
:::
Browser compatibility #
::: _table Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
sub
1 12 1 Yes 15 ≤4 4.4 18 4 14 ≤3.2 1.0
:::
See also #
::: section-content
- The
<sup>
HTML element that produces superscript. Note that you cannot usesup
andsub
both at the same time: you need to use MathML to produce both a superscript directly above a subscript next to the chemical symbol of an element, representing its atomic number and its nuclear number. - The
<msub>
,<msup>
, and<msubsup>
MathML elements. - The CSS
vertical-align
property. :::
::: _attribution
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5
or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sub{._attribution-link}
:::