MDUtil

Superscript and Subscript in Markdown

Standard Markdown has no superscript or subscript syntax, so <sup> and <sub> do the job: x<sup>2</sup>, H<sub>2</sub>O. This guide also covers math, Unicode characters and the shorthand some apps add.

Quick answer

How do you write superscript and subscript in Markdown?

Use the HTML tags <sup> and <sub>: x<sup>2</sup> raises the 2 and H<sub>2</sub>O lowers it. They work on GitHub and in most apps that allow HTML. Pandoc and Typora also read ^text^ and ~text~.

Markdown
E = mc<sup>2</sup> and H<sub>2</sub>O

Result

E = mc2 and H2O

Superscript and subscript examples

Pick the method by where the text will be shown.

Superscript with <sup>

For exponents, ordinals and reference marks.

Markdown
10<sup>-3</sup> seconds, 1<sup>st</sup> place, a note<sup>1</sup>

Result

10-3 seconds, 1st place, a note1

Subscript with <sub>

For chemical formulas and indexes.

Markdown
CO<sub>2</sub>, x<sub>i</sub>, log<sub>2</sub> 8 = 3

Result

CO2, xi, log2 8 = 3

Math notation

Where math is supported, ^ and _ inside dollar signs write proper formulas.

Markdown
$x^2 + y^2 = r^2$ and $\mathrm{H_2O}$

Result

x2+y2=r2x^2 + y^2 = r^2 and H2O\mathrm{H_2O}

Unicode characters

Superscript and subscript digits are ordinary characters, so they show up everywhere, chat apps included.

Markdown
x² + y² = r², H₂O, 10⁻³

Result

x² + y² = r², H₂O, 10⁻³

Nesting and formatting

The tags can hold Markdown and other tags, even each other.

Markdown
2<sup>2<sup>2</sup></sup> = 16 and Price<sup>**new**</sup>

Result

222 = 16 and Pricenew

Pandoc and Typora: carets and tildes

Pandoc reads ^text^ as superscript and ~text~ as subscript; Typora does once the options are on. On GitHub a single tilde means strikethrough.

Markdown
x^2^ and H~2~O

Pandoc and Typora only. Other Markdown apps display this differently, so there is no preview.

Superscript and subscript in popular apps

The HTML tags work wherever inline HTML is kept.

AppSupportNotes
GitHub / GitLabSupported<sup> and <sub> work; math with ^ and _ too.
ObsidianSupported<sup> and <sub> work in reading view.
TyporaSupportedThe tags work, and ^text^ and ~text~ once turned on in the settings.
NotionNot supportedNo typed syntax; use an inline equation or Unicode characters.
Discord / SlackNot supportedNo superscript; Unicode characters such as ² still display.

Questions and answers

Does Markdown have superscript syntax?

Not in CommonMark or GitHub Flavored Markdown. Use <sup> and <sub> where HTML is allowed; Pandoc and Typora also read ^text^ and ~text~.

How do I write superscript on GitHub?

Use <sup>: x<sup>2</sup>. GitHub also renders math, so $x^2$ works as well.

Why does ~text~ strike text through instead of lowering it?

In GitHub Flavored Markdown, one tilde on each side is strikethrough. Use <sub> for subscripts there.

How do I write a chemical formula?

Use <sub>: H<sub>2</sub>O, or math: $\mathrm{H_2O}$. Unicode subscript digits such as ₂ also work in plain text.

How do I add superscript in Discord or Slack?

Neither has superscript. Type Unicode characters such as ² and ³, which display everywhere.

Do superscripts survive a Word or PDF export?

Yes. Markdown to Word turns <sup> and <sub> into Word superscript and subscript, and Markdown to PDF prints them.