Markdown Subscript and Superscript: What Works on GitHub, Pandoc, R Markdown, Obsidian and Notion

Standard Markdown has no subscript or superscript. Here is what does work on each platform: <sub>/<sup> on GitHub and GitLab, ~x~ and ^x^ in Pandoc, R Markdown, Quarto and Typora, math on Obsidian and Notion, and Unicode where nothing else is available.

Short answer: standard Markdown has no subscript or superscript syntax. Use the HTML tags H<sub>2</sub>O and x<sup>2</sup>, which work on GitHub, GitLab and most editors. In Pandoc, R Markdown, Quarto and Typora you can also write H~2~O and x^2^. Where neither works, paste Unicode characters (H₂O, x²) from the Subscript Generator or Superscript Generator.

The rest of this page is the detail: which syntax each platform accepts, where the tilde collides with strikethrough, and what to do in apps with no HTML.

Syntax by platform

Platform Subscript Superscript Notes
CommonMark (the Markdown spec) none none Raw HTML passes through, so <sub> and <sup> work wherever the renderer allows HTML
GitHub (README, issues, comments) <sub>2</sub> <sup>2</sup> Listed in GitHub's own formatting docs
GitLab <sub>2</sub> <sup>2</sup> GitLab's docs say it does not support the x^2 shorthand
Pandoc H~2~O 2^10^ Spaces inside must be escaped: P~a\ cat~
R Markdown H~3~PO~4~ Cu^2+^ Uses Pandoc, so the same rules apply
Quarto subscript~2~ superscript^2^ Uses Pandoc
Typora H~2~O X^2^ Off by default: enable it in Preferences, Markdown tab
markdown-it (with plugins) H~2~O with markdown-it-sub 29^th^ with markdown-it-sup Not on by default; both plugins follow the Pandoc rules
Obsidian <sub>2</sub> or math $H_2O$ <sup>2</sup> or math $x^2$ Obsidian's help documents MathJax for math; it does not document sub/sup
Notion inline equation $$H_2O$$ inline equation $$x^2$$ Text becomes an equation, in equation font
Discord, Slack none none Use Unicode characters
Word, Google Docs Word: Ctrl+Shift+Minus. Docs: Ctrl+, Word: Ctrl+Shift+Plus. Docs: Ctrl+. Mac Google Docs: ⌘+, and ⌘+.

Sources are the platforms' own documentation: GitHub "Basic writing and formatting syntax", GitLab "GitLab Flavored Markdown", the Pandoc manual (superscript and subscript extension), the R Markdown book, Quarto "Markdown Basics", Typora "Markdown Reference", Notion "Math equations", Microsoft Support and Google Docs Editors Help.

HTML tags: the one that works almost everywhere

Water is H<sub>2</sub>O.
Einstein wrote E = mc<sup>2</sup>.
This is the 21<sup>st</sup> century.

Water is H2O.
Einstein wrote E = mc2.
This is the 21st century.

This is the safe default for anything that will be read on GitHub or GitLab, and it is what most Markdown editors with a preview render correctly. Two things to know:

Situation What happens
Renderer strips or escapes HTML (some comment systems, chat apps, safe-mode wikis) You see the literal tags <sub>2</sub>
Markdown inside the tag, like <sup>**2**</sup> Works on GitHub. Some renderers leave the asterisks as text, so test before you rely on it
Nested tags, like x<sup>y<sup>2</sup></sup> Valid HTML and renders on GitHub, but tiny and hard to read. Use math instead

Pandoc syntax: ~sub~ and ^sup^

Pandoc, R Markdown and Quarto all use the same rule: wrap subscript text in single tildes and superscript text in carets.

H~2~O is a liquid. 2^10^ is 1024.
Phosphoric acid is H~3~PO~4~ and copper ions are Cu^2+^.

The rule people trip on is spaces. The Pandoc manual says the text between the markers "may not contain spaces or newlines", and spaces must be escaped with a backslash:

You write Result
x^2^ x2
T~max~ Tmax
P~a cat~ Not converted: the space ends it
P~a\ cat~ Pa cat
x^n+1^ xn+1 (no spaces, so fine)

The Superscript Generator and Subscript Generator produce this form with the spaces already escaped, under "Pandoc Markdown".

The tilde collision with strikethrough

On GitHub, a pair of tildes is strikethrough. GitHub's docs show ~~text~~, and its renderer also accepts single tildes, so H~2~O written for R Markdown shows up on GitHub as H with a struck-through 2. If one file has to render in both places (a README that is also knitted), use the HTML tags. Our strikethrough guide has the platform table for tildes.

File will be read in Use
R Markdown, Quarto, Pandoc only H~2~O
GitHub or GitLab H<sub>2</sub>O
Both H<sub>2</sub>O (Pandoc passes raw HTML through to HTML output)

One more R Markdown note: <sub> passes through to HTML output, but not to PDF via LaTeX. For a document you knit to both HTML and PDF, ~2~ is the portable choice.

Math syntax: $x^2$ and $H_2O$

If the platform renders math, superscripts and subscripts come for free: ^ raises and _ lowers, with braces for more than one character.

Inline: $x^2 + y^2 = z^2$ and $a_{n+1} = a_n + d$
Platform Inline math delimiter
GitHub $...$ or $`...`$ (rendered with MathJax)
GitLab $...$ or $`...`$
Obsidian $...$ (MathJax)
Notion $$...$$ typed inline turns into an inline equation
Jupyter, Quarto, R Markdown $...$

Use math for formulas, not for ordinary words. Letters in math mode are italic variables, so $21^{st}$ looks like a formula. For chemistry, $\mathrm{H_2O}$ keeps the letters upright. Notion's help page makes the same point: sub and superscript through equations work, but the text "will be an equation, in equation font". Our Markdown Math Editor previews LaTeX as you type.

Unicode characters: for places with no formatting

Discord, Slack, social posts, spreadsheet cells, file names and commit messages have no subscript or superscript at all. There, the only option is characters that are already small: ², ₂, ⁿ, ₓ.

Set Characters available Missing
Superscript digits and signs ⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁺ ⁻ ⁼ ⁽ ⁾ none
Superscript lowercase ᵃ ᵇ ᶜ ᵈ ᵉ ᶠ ᵍ ʰ ⁱ ʲ ᵏ ˡ ᵐ ⁿ ᵒ ᵖ ʳ ˢ ᵗ ᵘ ᵛ ʷ ˣ ʸ ᶻ q
Superscript capitals ᴬ ᴮ ᴰ ᴱ ᴳ ᴴ ᴵ ᴶ ᴷ ᴸ ᴹ ᴺ ᴼ ᴾ ᴿ ᵀ ᵁ ⱽ ᵂ C F Q S X Y Z
Subscript digits and signs ₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ₊ ₋ ₌ ₍ ₎ none
Subscript letters ₐ ₑ ₕ ᵢ ⱼ ₖ ₗ ₘ ₙ ₒ ₚ ᵣ ₛ ₜ ᵤ ᵥ ₓ all capitals, and b c d f g q w y z

Digits are complete in both directions, so chemical formulas (H₂O, CO₂, C₆H₁₂O₆) and exponents (10⁻³, m²) work well. Words often do not: there is no subscript c for Tc and no subscript f for vfinal. The generators tell you which characters they could not convert.

Caveats that apply to all Unicode tricks:

Issue Effect
Search Searching for "H2O" will not find "H₂O"
Screen readers May read "subscript two" or skip the character
Fonts The letters come from phonetic alphabets and are drawn at uneven sizes
Spreadsheets m² is text; a formula will not read it as "squared"

Common problems

Problem Cause Fix
<sub>2</sub> shows as text The app escapes HTML Use the app's math syntax, or Unicode
H~2~O shows a struck-through 2 GitHub treats tildes as strikethrough Use <sub> on GitHub
x^2^ shows the carets Renderer is not Pandoc-based (GitHub, GitLab, Obsidian, CommonMark) Use <sup>, or turn the option on in Typora
P~a cat~ not converted in R Markdown Unescaped space P~a\ cat~
Footnote looks like [^1] superscript That is footnote syntax, not superscript Footnotes are a separate feature; see the footnote generator
Ordinal "1st" in a formula looks odd Math mode italicizes letters 1<sup>st</sup> or ¹ˢᵗ

Which one to use

You are writing Use
A GitHub or GitLab README, issue or wiki <sub> and <sup>
An R Markdown, Quarto or Pandoc document ~x~ and ^x^
Formulas with several levels Math: $x_{i}^{2}$
Notes in Obsidian <sup> for text, $...$ for formulas
Notion Inline equation
Discord, Slack, a tweet, a spreadsheet Unicode from the Superscript Generator or Subscript Generator

For smaller text that is not raised or lowered, see small text in Markdown.