Chapter 5 • Lesson 5.6

Superscript <sup> & Subscript <sub>

Mastering mathematical powers, chemical formulas, and academic footnotes while solving the notorious browser line-height vertical alignment bug.

🎯 Learning Objectives

📖 Mental Model: The Typographic Elevators

Imagine the baseline of text is the ground floor of a building:

1. The Common Use Cases for <sup> and <sub>

Element Field Example Expression Semantic HTML Markup
<sup> Mathematics Pythagorean Theorem: $a^2 + b^2 = c^2$ a<sup>2</sup> + b<sup>2</sup> = c<sup>2</sup>
<sup> Physics Mass-Energy Equivalence: $E = mc^2$ E = mc<sup>2</sup>
<sup> Typography Ordinal Numbers: 1st, 2nd, 3rd 1<sup>st</sup>, 2<sup>nd</sup>
<sup> Publishing Footnote Citation Reference: [1] <sup><a href="#fn1">[1]</a></sup>
<sub> Chemistry Water: $\text{H}_2\text{O}$, Carbon Dioxide: $\text{CO}_2$ H<sub>2</sub>O, CO<sub>2</sub>
<sub> Biochemistry Glucose: $\text{C}_6\text{H}_{12}\text{O}_6$ C<sub>6</sub>H<sub>12</sub>O<sub>6</sub>
<sub> Computer Science Logarithm Base 2: $\log_2(n)$ log<sub>2</sub>(n)

2. The Infamous Line-Height Breakdown & CSS Fix

By default, browser User-Agent stylesheets apply vertical-align: super and vertical-align: sub. Because this shifts the character box outside the normal line boundary, it forces the browser to expand the line-height of that single line, resulting in uneven, jagged paragraph spacing.

DEFAULT BROWSER BEHAVIOR (BROKEN LINE SPACING): Line 1: Normal paragraph line of text here... Line 2: Contains H₂O and Einstein's E=mc² right here! <-- EXPANDS LINE GAP! Line 3: Notice how the gap above Line 3 is suddenly 4px wider than normal! MODERN CSS NORMALIZATION (FLAWLESS UNIFORM SPACING): Line 1: Normal paragraph line of text here... Line 2: Contains H₂O and Einstein's E=mc² right here! <-- Perfect line spacing preserved! Line 3: Uniform and perfectly aligned leading across the entire paragraph.

Here is the standard CSS normalization used by modern frameworks (including Normalize.css and Tailwind):

/* Standard CSS Fix for <sup> and <sub> Line Height Distortion */ sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } sup { top: -0.5em; } sub { bottom: -0.25em; }

3. Interactive Chemistry & Physics Laboratory

Observe the chemical reaction and algebra theorem below with clean superscript exponents and subscript molecular formulas.

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL index.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45°C
INSPECTING DOM: VALID
TAGS: SCANNING...

🏋️ Hands-On Exercise: Formatting a Scientific Exam Question

  1. Format sulfuric acid "H2SO4" into proper chemical subscripts using <sub>.
  2. Format the algebraic polynomial "3x3 + 5x2 - 7x + 2 = 0" using <sup> for powers.
  3. Format the date "October 1st" using <sup> for the ordinal indicator.
  4. Click ▶ Run Code and verify the mathematical and scientific formatting.
SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL exercise.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45°C
INSPECTING DOM: VALID
TAGS: SCANNING...

⚠️ Pitfall: Screen Reader Pronunciation of Formulas

Screen readers may read H<sub>2</sub>O as "H two O" or "H subscript two O". For complex equations, consider providing an aria-label or utilizing MathML (<math>) for deep mathematical accessibility.

💡 Pro Tip: OpenType True Font Superscripts

Modern web fonts often contain specially drawn superscript glyphs with matching stroke weight. You can activate them with CSS:

sup { font-variant-position: super; /* Uses designed OpenType glyphs if available */ }

📌 Key Takeaways

⭐ LEARN: HTML 🌟 ⚔️ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

What causes unstyled <sup> and <sub> elements to create irregular line gaps inside paragraphs?

Question 1 / 3 Topic: HTML Fundamentals
14:28 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 2 / 3

Which element is semantically correct for marking the '2' in the chemical formula for carbon dioxide (CO₂)?

Question 2 / 3 Topic: HTML Fundamentals
14:28 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 3 / 3

How does the industry-standard CSS fix neutralize line-height distortion for <sup> and <sub>?

Question 3 / 3 Topic: HTML Fundamentals
14:28 REMAINING
XP REWARD
+250 XP