# Write chemical formulas without flattening subscripts

Canonical: https://githtml.com/guides/chemical-formulas-sub-sup-html
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

Use sub and sup for conventional subscripts and superscripts in short formulas, and provide the compound or quantity's name in nearby text. Do not use smaller text alone to imply position. Complex scientific notation may require MathML, while simple HTML notation should remain understandable when copied or read aloud.

## Choose the right representation

An ordinary digit and a subscript digit can mean different things. In a laboratory note, H2O with an unexplained baseline numeral is less precise than a properly presented formula accompanied by the word water. The markup gives the browser a conventional typographic instruction, but the surrounding sentence supplies the scientific context.

## Apply the pattern deliberately

Reserve subscript for notation that genuinely calls for it, not decorative labels. For charges and exponents, use superscript and make the scope clear. Avoid manually inserting spaces to align several formulas. Different fonts, text sizes, and line breaks will destroy that alignment. A small list with one formula and one explanation per item is often more dependable.

1. Pair each unfamiliar formula with its ordinary name or an explicit explanation of the notation.
2. Check subscripts and superscripts at larger text sizes and in the chosen fallback font.
3. Use structured mathematical markup when nested notation becomes difficult to express unambiguously.

````html
<p>Water: H<sub>2</sub>O.</p>
<p>The unit is square metres: m<sup>2</sup>.</p>
````

## Keep position, meaning, and copying separate

Distinguish a count within a formula from a coefficient before it. In a teaching example, the two in H2O describes part of one formula, while a leading two can describe two units of that formula. Presenting both digits as identical small decorations obscures the distinction. Explain the convention before using several formulas in a table. This is especially important when a document mixes chemical notation with variable subscripts from a mathematical model.

A superscript charge and a superscript power can look similar but mean different things. Name the ion or quantity and explain the notation in the sentence, rather than relying on the raised character alone. Avoid replacing semantic markup with Unicode lookalike characters simply because they seem convenient in one font. The available glyphs, text selection, and spoken result can differ. Use a consistent representation within the document and verify the characters that leave the page when copied.

Check a formula inside an ordinary sentence as well as in a large display heading. A stylesheet that forces a tiny line height may create collisions even though the isolated heading looks excellent. Print or export a representative passage if that is part of the delivery workflow. For formulas involving nested scripts or a more elaborate mathematical structure, prefer an authoring method that preserves those relationships and keep the explanatory names beside the result.

## Check the finished reading experience

Check whether the baseline shifts create unusually tall or crowded lines. Readers should be able to identify both the letters and the small numerals without guessing. When copying loses visual placement, the adjacent name or verbal explanation should still identify the intended substance or relationship.

## Sources and further reading

- [MDN: sub](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/sub)

## Related guides

- [Move a reading task between iPhone and iPad without losing context](https://githtml.com/guides/move-reading-between-iphone-ipad-without-losing-context)
- [Read technical HTML comfortably on iPad in portrait and landscape](https://githtml.com/guides/read-technical-html-ipad-portrait-landscape)
- [Build a small GitHub document reading queue with favorites and recents](https://githtml.com/guides/favorites-recents-document-reading-queue)
- [Find answers in long HTML reports with better search queries](https://githtml.com/guides/search-long-html-report-with-better-queries)

Editorial approach: https://githtml.com/guides/about
