HTML
Subscript element
(
<sub>
) specifies inline text which should be displayed as subscript for solely typographical reasons.
Subscripts are typically rendered with a lowered baseline using smaller text.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
| 内容类别 | 流内容 , 措词内容 ,可触及内容。 |
|---|---|
| 准许内容 | 措词内容 . |
| Tag omission | None, both the starting and ending tag are mandatory. |
| Permitted parents | Any element that accepts 措词内容 . |
| Implicit ARIA role | 无对应角色 |
| Permitted ARIA roles | 任何 |
| DOM 接口 |
HTMLElement
|
此元素只包括 全局属性 .
<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
would not be appropriate; instead, CSS should be used (likely the
vertical-align
property, such as
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):
Traditional footnotes are denoted using numbers which are rendered in subscript. This is a common use case for
<sub>
:
<p>According to the computations by Nakamura, Johnson, and Mason<sub>1</sub> this will result in the complete annihilation of both particles.</p>
The resulting output looks like this:
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:
<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>
The resulting output:
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:
<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>
The output:
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of '<sub> and <sup>' in that specification. |
实时标准 | |
|
HTML5
The definition of '<sub> and <sup>;' in that specification. |
推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
sub
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
完整支持
<sup>
HTML element that produces superscript. Note that you cannot use them both at the same time and 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.
<msub>
,
<msup>
,和
<msubsup>
MathML elements.
vertical-align
特性。