Subscript and Superscript in Markdown
Markdown subscript has no native syntax. Use the sub and sup HTML tags, Pandoc's tilde and caret, or LaTeX math — and know where each one works.
Short answer: Neither CommonMark nor GitHub Flavored Markdown has a markdown subscript or superscript syntax. Use the HTML tags <sub> and <sup>, which work on GitHub, GitLab, Obsidian, and most static site generators. Pandoc and a few other parsers support ~subscript~ and ^superscript^. For equations and scientific notation, LaTeX math is the better answer.
This is one of the clearer cases where markdown just doesn't cover something. There's no consensus syntax, three competing approaches, and the right choice depends on whether you're writing a chemical formula, a mathematical expression, or an ordinal number in prose.
The HTML Approach (Most Portable)
Water is H<sub>2</sub>O and carbon dioxide is CO<sub>2</sub>.
The area is r<sup>2</sup> times pi.
This was the 1<sup>st</sup> attempt.
<sub> lowers and shrinks the text; <sup> raises and shrinks it. Both are standard HTML elements with real semantics — screen readers and search engines understand them, and they've been in the spec since HTML 2.0.
This works anywhere raw HTML passes through a markdown renderer, which is most places. It's what GitHub's own documentation recommends, because GitHub has no markdown syntax for it either.
Two things to know:
No spaces inside the tags. <sub> 2 </sub> adds visible whitespace to the rendered output.
Markdown inside the tags is inconsistent. <sup>**bold**</sup> may or may not render the bold, depending on whether the parser re-enters markdown mode inside an inline HTML span. Keep the content plain.
The Pandoc Approach
Pandoc — and parsers that copy its extensions, including Quarto, R Markdown, and some markdown-it configurations — supports a dedicated syntax:
H~2~O
x^2^
Tildes for subscript, carets for superscript. No spaces allowed inside; if the content contains a space, escape it with a backslash: x^2\ times^.
It's cleaner to read in raw source than HTML tags, and it's the right choice if you're writing for a Pandoc-based toolchain. It is also the least portable option on this page. Paste H~2~O into GitHub and you get "H" followed by a struck-through 2, because GFM reads single tildes as strikethrough. Paste x^2^ into GitHub and you get literal carets.
Never use the Pandoc syntax in a document that might end up on GitHub.
The LaTeX Math Approach
For anything mathematical, math mode is the correct tool rather than a workaround:
Inline: $x^2 + y^2 = z^2$
Display:
$$
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
$$
In math mode, ^ is superscript and _ is subscript, and they're part of a full typesetting system — proper spacing around operators, correct italic styling for variables, stacked fractions, matrices, and limits. Wrap multi-character scripts in braces: x^{10} and a_{ij}.
Math renders through KaTeX or MathJax. GitHub supports it in READMEs and issues, most static site generators support it with a plugin, and Obsidian supports it natively. OpenMark renders both inline and display math with KaTeX bundled into the app, so it works with no network connection. Our LaTeX math in markdown guide covers the full syntax and where it's supported.
The chemistry caveat. Math mode italicizes letters because it assumes they're variables. $H_2O$ renders with a slanted H and O, which is wrong for a chemical formula — element symbols are upright. The correct math-mode version is:
$\mathrm{H}_2\mathrm{O}$
That's verbose enough that H<sub>2</sub>O is usually the better call for chemistry in prose.
Which to Use
| Use case | Best approach |
|---|---|
| Chemical formulas in prose | <sub> HTML |
| Ordinals (1st, 2nd, 3rd) | <sup> HTML |
| Trademark and footnote markers | <sup> HTML, or real footnotes |
| Mathematical variables and exponents | LaTeX math |
| Equations of any complexity | LaTeX math, display mode |
| Isotope notation, units with exponents | LaTeX math if the document already uses it, <sup> otherwise |
| Anything for a Pandoc-only pipeline | ~ and ^ |
The dividing line: if the content is mathematics, use math mode and get correct typography for free. If the content is text that happens to sit high or low, use HTML and keep it simple.
Where Each Works
| Platform | <sub> / <sup> | ~x~ / ^x^ | LaTeX math |
|---|---|---|---|
| GitHub / GitLab | Yes | No | Yes |
| Obsidian | Yes | No (plugin only) | Yes |
| Pandoc | Yes | Yes | Yes |
| Quarto / R Markdown | Yes | Yes | Yes |
| Hugo / Jekyll / Astro | Yes | No | With a plugin |
| MkDocs | Yes | With an extension | With an extension |
| Reddit / Discord / Slack | No | Reddit only, superscript | No |
| OpenMark | Yes | No | Yes |
Reddit is the outlier: it has its own caret syntax for superscript (^word, no closing caret) that exists nowhere else, and no subscript at all.
Unicode: Tempting, and Usually Wrong
There are Unicode characters for some subscripts and superscripts — H₂O, x², 10⁻³. They need no markdown, no HTML, and no renderer support, and they survive anywhere text survives, including Slack, Discord, and filenames.
The problems: the character set is incomplete (there is no superscript q, and the subscript letters are patchy), the glyphs are inconsistently sized across fonts, and screen readers announce them unpredictably — x² may be read as "x two". Copy-pasting into a search box or a code editor often produces something unusable.
Unicode is fine for a chat message or a filename. For documentation, use HTML or math mode.
Footnote Markers Deserve Real Footnotes
A common reason people reach for <sup> is a footnote marker:
This claim needs a source.<sup>1</sup>
That gives you a raised number and nothing else — no link, no backlink, no automatic numbering, and renumbering by hand every time you insert a note. GFM has actual footnote syntax that handles all of it:
This claim needs a source.[^1]
[^1]: Source goes here.
See how to add footnotes in markdown for the full syntax and where it's supported. Use <sup> for things that are genuinely just raised text — ordinals, trademark symbols, unit exponents — and real footnotes for references.
For the broader picture of what GFM adds on top of standard markdown, see markdown extensions: GFM and MDX.
Download OpenMark → — $9.99, one-time, native macOS. HTML tags, LaTeX math via bundled KaTeX, and Mermaid diagrams, all rendered offline.