Nearby lessons

22 of 24

🔽 <sub> Tag

📌 What is the <sub> Tag?

The <sub> HTML tag is used to define subscript text. Subscript text appears half a character below the normal line and is typically used in chemical formulas or mathematical expressions.

Example usage includes H2O or CO2.

📌 Syntax

Use the <sub> tag to wrap the text you want to appear as subscript.
Example02
🌐Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔍 Use Cases

  • Chemical formulas (e.g., CO2)
  • Mathematical expressions (e.g., an)
  • Footnotes or citations in academic writing

⚙️ Attributes

AttributeDescription
Global AttributesThe <code>&lt;sub&gt;</code> tag supports all global attributes in HTML.
Event AttributesSupports event attributes like <code>onclick</code>, <code>onmouseover</code>, etc.

✅ Best Practices

  • Use <sub> only for subscript semantics, not visual styling.
  • Avoid overusing subscript in body text to maintain readability.
  • Pair <sub> with <sup> when both are needed (e.g., chemical equations).
  • Use semantic tags for clarity and accessibility, especially in academic or scientific contexts.
  • Use CSS for layout and styling rather than relying on <sub> for spacing or alignment.

🧠 Test Your Knowledge

2 Questions
Progress: 0 / 2