HTML <sub> Tag

Beginner
5 min read
Updated: Nov 2026
4 examples
Live preview

Definition and Usage

The <sub> element marks inline text that should appear as a subscript for typographical reasons. Browsers typically lower the baseline and use slightly smaller text.

Good fits: chemical formulas (H2O), math indices (<var>, and footnote markers. For raised text use <sup>. For decoration-only lowering use CSS vertical-align, not <sub>.

Baseline · Widely available.

Not deprecated and not experimental. Stable across modern browsers since about July 2015.

Typography, not decoration.

Use <sub> when convention calls for a subscript. Do not use it only to shrink or drop letters in a logo or heading.

HTML Syntax

syntax.html
<sub> subscript text</sub>

Both start and end tags are required. Content is phrasing content (text and inline elements).

Attributes

<sub> has no element-specific attributes. Use globals when needed:

AttributeDescriptionTry it
classOptional CSS hook if you restyle subscriptsTry it
idUnique identifier for linking or scriptingGlobal attr
titleAdvisory text (tooltip). Rarely needed on subOptional

Global Attributes

The <sub> tag also supports the Global Attributes in HTML.

Live Preview

Switch common subscript uses and see how <sub> reads in context.

Real <sub> markup for typographical subscripts.

Result

Water is H2O.

Chemical formula — atom count in subscript.

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Chemical Formula

Wrap atom counts in <sub> so the formula follows chemistry typography.

HTML
<p>
  Water is H<sub>2</sub>O.
</p>
<p>
  Caffeine is C<sub>8</sub>H<sub>10</sub>N<sub>4</sub>O<sub>2</sub>.
</p>
Try It Yourself

How It Works

  1. Write the element symbols as normal text (H, O, C, …).
  2. Wrap each atom count in <sub>…</sub>.
  3. Keep both tags — start and end are required.
  4. Do not use sub for letters that are just part of a brand look.

Example 2 — Math Variable Index

Combine <var> with <sub> for indexed variables.

HTML
<p>
  Positions on the X-axis:
  <var>x<sub>1</sub></var> …
  <var>x<sub>n</sub></var>.
</p>
Try It Yourself

How It Works

  1. Wrap the variable in <var>.
  2. Put the index inside <sub> inside that var.
  3. Keep indices short (numbers or simple letters).
  4. For complex equations, consider MathML instead of plain HTML alone.

Example 3 — Footnote Marker

Traditional footnote numbers are often shown in subscript.

HTML
<p>
  According to Nakamura et al.<sub>1</sub>
  the particles annihilate.
</p>
Try It Yourself

How It Works

  1. Place the marker right after the referenced phrase.
  2. Wrap the number in <sub>.
  3. Link to the note with an <a> when you have a footnotes list.
  4. Keep markers readable — do not nest heavy markup inside sub.

Example 4 — sub vs sup

Subscript lowers; superscript raises. Use the one that matches the convention.

HTML
<p>Water: H<sub>2</sub>O</p>
<p>Squared: x<sup>2</sup></p>
Try It Yourself

How It Works

  1. First line: atom count uses <sub>.
  2. Second line: exponent uses <sup>.
  3. Same idea, opposite direction — lower vs raise.
  4. Pick by convention, not by whichever looks smaller.

Edge Cases & Pitfalls

Most mistakes use sub as a style knob instead of a typographical mark.

decoration

Not for logos or layout tricks

If you only want lowered letters for looks, use CSS vertical-align (or similar). Save <sub> for real subscripts.

vs sup

Do not swap with sup

Exponents and ordinals usually need <sup>. Atom counts and indices usually need <sub>.

math

Complex math may need MathML

Simple indices work with sub. Large formulas are clearer with MathML than many nested HTML tags.

a11y

Implicit role is subscript

Assistive tech can expose subscript. Keep the content short so the spoken formula stays clear.

nesting

Avoid deep nesting

Do not stack many sub / sup levels for layout. Prefer a formula language when structure gets heavy.

Browser Support

The <sub> element is core HTML in every browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<sub>

Widely available since about July 2015 (and long before as subscript). Chrome, Firefox, Safari, Edge, and Opera all support it fully.

98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported
<sub> Widely supported

Bottom line: Safe to use everywhere for typographical subscripts. Choose sub or CSS by meaning — not only by the lowered look.

Key Takeaways

  • Role: <sub> marks typographical subscripts.
  • Use for: formulas, math indices, and footnote markers.
  • Compare: sup raises text; CSS lowers for decoration only.
  • Pairing: <var>x<sub>1</sub></var> is a common math pattern.

One line: use <sub> when typography needs a real subscript — not just smaller text.

Default CSS Settings

Typical user-agent styling (browsers may add more details):

default.css
sub {
  vertical-align: sub;
  font-size: smaller;
}

You may restyle sub with CSS, but keep it clearly lowered so formulas stay readable.

Frequently Asked Questions

The sub element marks inline text that should appear as a typographical subscript — for example atom counts in chemical formulas, math indices, or footnote markers.
Visually they can look similar. Use sub when the subscript is part of typographical convention (formulas, indices). Use CSS when you only want a lowered look for decoration or branding.
sub lowers text (subscript). sup raises text (superscript), often used for exponents or ordinals. Pick the one that matches the convention.
No. sub only supports the global attributes, such as class, id, and lang.
No. That is presentation. Style the logo with CSS (for example vertical-align) instead of sub.
Yes. A common math pattern is <var>x<sub>1</sub></var> for a subscripted variable.

Next: summary

Learn the summary element used as a disclosure label for details.

summary tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful