Skip to main content

How to Write Superscript and Subscript in Markdown

CommonMark has no raised or lowered type. This guide covers the HTML tags that work on GitHub, Reddit's caret, Pandoc's caret and tilde extensions, and the math forms for real formulas.

Short answer

Use <sup> and <sub> on GitHub, GitLab, Obsidian, and VS Code. Reddit only has ^word. Pandoc and R Markdown add ^super^ and ~sub~. Discord and Slack have neither.

HTML Superscript and Subscript

Most Markdown renderers pass a safe subset of HTML through. <sup> raises text, <sub> lowers it. GitHub keeps both tags. That is the portable method for README files, docs sites, and note apps that allow HTML.

Superscript
E = mc<sup>2</sup>
Preview

E = mc2

Subscript
H<sub>2</sub>O and CO<sub>2</sub>
Preview

H2O and CO2

Both on one ion
The ion is SO<sub>4</sub><sup>2-</sup>.
Preview

The ion is SO42-.

Inline in a sentence
See footnote <sup>1</sup> and the formula H<sub>2</sub>O.
Preview

See footnote 1 and the formula H2O.

Keep the tags inline. Unlike a centered <div>, these are phrasing elements, so you do not need blank lines around them.

Markdown Subscript

Subscript has the same gap as superscript: CommonMark defines nothing. Reach for HTML first. The tilde form only exists in Pandoc-family tools, and Reddit never added a lowered-type marker.

You wantWriteWhere it works
Water, body textH<sub>2</sub>OGitHub, GitLab, Obsidian, VS Code
Water, Pandoc sourceH~2~OPandoc, R Markdown
Water, a formula$H_2O$GitHub math, Obsidian MathJax
Water, on RedditNo subscript. Write H2O or use ₂.Reddit

GitHub Math for Exponents

When the raised or lowered characters are part of a formula, GitHub's LaTeX math is cleaner than HTML tags. Inline math uses one dollar sign on each side. A caret is an exponent, an underscore is a subscript. Multi-character exponents need braces: $x^{10}$.

Inline exponentGitHub math
The area is $x^2$.
How it looks on GitHub

The area is .

Inline subscriptGitHub math
Water is $H_2O$.
How it looks on GitHub

Water is H₂O.

Display equationGitHub math
$$a^2 + b^2 = c^2$$
How it looks on GitHub

a² + b² = c²

Use HTML when you want the surrounding sentence font; use math when you are actually writing math. See the GitHub Markdown guide for the rest of GFM.

Reddit Superscript

Reddit is the one mainstream Markdown surface with a native raised-type marker: a caret before the text. There is no subscript, and HTML is stripped.

Single word or characterReddit only
E = mc^2
How it looks on Reddit

E = mc2

Several words, caret on eachMost reliable
^like ^this
How it looks on Reddit

like this

Parentheses, often wrong on old RedditAvoid
^(like this)
How it looks on www.reddit.com

like this

Avoid ^(...) when the raised text contains a link. Full rules live on the Reddit formatting guide.

Pandoc and R Markdown

Pandoc and R Markdown add two extensions CommonMark never took. Wrap raised text in carets and lowered text in tildes. Spaces inside the span must be escaped.

Pandoc superscriptPandoc / Rmd
2^10^ is 1024.
How Pandoc renders it

210 is 1024.

Pandoc subscriptPandoc / Rmd
H~2~O is a liquid.
How Pandoc renders it

H2O is a liquid.

Spaces must be escapedPandoc / Rmd
n^th\ term^
How Pandoc renders it

nth term

Do not paste these into a GitHub README. GitHub will print the carets and tildes. Keep <sup> / <sub> in files that render on GitHub.

Discord, Slack, and Unicode

Chat apps strip HTML and never added raised or lowered type. Discord's -# prefix is subtext, not a subscript. Slack's mrkdwn has nothing in this neighborhood.

MeaningPaste
Common superscripts¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁰ ⁺ ⁻
Common subscripts₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ₊ ₋

Unicode only covers a handful of characters. See the Discord text formatting guide for the features Discord actually has.

Common Mistakes

Most failures are a syntax from one renderer pasted into another.

Broken

x^2 + y^2 = z^2

Fixed

x<sup>2</sup> + y<sup>2</sup> = z<sup>2</sup>
A bare caret is not superscript in CommonMark or GitHub Flavored Markdown. It prints as a caret. Wrap the raised text in <sup>, or use math mode if you are writing a real formula.

Broken

H~2~O

Fixed

H<sub>2</sub>O
Paired tildes are a Pandoc and R Markdown extension. On GitHub they stay literal. GFM strikethrough is two tildes (~~text~~), which is a different feature.

Broken

^(two words)

Fixed

^two ^words
The parenthesized Reddit form often misparses on old Reddit, especially when the raised text contains a link. Put a caret in front of each word instead.

Broken

-# smaller text

Fixed

Paste ² or write it in Unicode
Discord's -# marker is subtext: smaller, muted body copy. It is not subscript. Discord and Slack have no raised or lowered type, so use a Unicode character or skip the formatting.

Quick Reference

SyntaxResultWorks on GitHub?
<sup>2</sup>Raised 2Yes
<sub>2</sub>Lowered 2Yes
$x^2$Math exponentYes (math font)
$H_2O$Math subscriptYes (math font)
^wordReddit superscriptNo
2^10^Pandoc superscriptNo
H~2~OPandoc subscriptNo
-# textDiscord subtextNo

Platform Support

Support splits on whether the renderer allows HTML, and whether it invented its own marker.

PlatformSupported?Notes
GitHubYes<sup> and <sub> are on the HTML allowlist. $x^2$ and $H_2O$ also work in math mode.
GitLabYesHTML tags work. The old Redcarpet x^2^ caret syntax does not.
VS Code previewYesThe built-in preview passes <sup> and <sub> through.
ObsidianYesReading view renders the HTML tags. MathJax $x^{2}$ and $H_{2}O$ work for formulas.
Pandoc / R MarkdownYesNative extensions: ^super^ and ~sub~. Spaces inside must be backslash-escaped.
RedditPartialCaret superscript only (^word). No subscript. HTML is stripped.
NotionNoPasted HTML becomes Notion blocks. Use an equation block for formulas.
DiscordNoNo HTML, no caret syntax. -# is subtext, not subscript. Unicode only.
SlackNomrkdwn has no raised or lowered type and strips HTML.
CommonMark / GFMPartialNo native syntax. Raw <sup> and <sub> pass through if the renderer allows HTML.

Frequently Asked Questions

How do you write superscript in Markdown?

CommonMark has no superscript syntax. On GitHub, GitLab, Obsidian, VS Code, and most static site generators, wrap the raised text in HTML: E = mc<sup>2</sup>. On Reddit, put a caret before the word: E = mc^2. In Pandoc or R Markdown, wrap it in carets: 2^10^.

How do you write subscript in Markdown?

There is no CommonMark subscript syntax either. Use HTML: H<sub>2</sub>O. That works on GitHub and any renderer that allows <sub>. Pandoc and R Markdown add a tilde form: H~2~O. Reddit has no subscript at all.

Does GitHub support superscript?

Yes. GitHub's HTML sanitizer keeps <sup> and <sub>, so they render in README files, issues, pull requests, and comments. For actual math, GitHub also renders LaTeX: $x^2$ inline or $$x^2$$ as a block. The HTML tags keep the surrounding body font; the math form uses a math font.

Does ^2 work as Markdown superscript?

Only on Reddit, and only as a caret immediately before the characters you want raised. In CommonMark, GFM, GitHub README files, Discord, and Slack, x^2 prints as x^2. On GitHub write x<sup>2</sup> or $x^2$.

How do I write H2O in Markdown?

Use a subscript tag: H<sub>2</sub>O. On GitHub you can also write the formula in math mode as $H_2O$. In Pandoc or R Markdown, H~2~O works. Reddit cannot lower the 2.

Does Reddit have subscript?

No. Reddit's formatter has caret superscript and nothing for subscript. HTML is stripped from posts and comments, so <sub> does not help. Spell the formula out or use a Unicode subscript character if you only need a digit.

Can I use superscript in Discord or Slack?

No. Both strip HTML and neither adds a raised-type marker. Discord's -# line is subtext (smaller, muted text), not a true subscript. Paste a Unicode character such as ² or ₂, or skip the formatting.

What is the difference between <sup> and math mode?

<sup>2</sup> raises a character in the same font as the sentence, which is what you want for footnote markers, ordinals, and units. $x^2$ is a math expression: it is the right tool for equations, but it renders in a math font and is overkill for a single ordinal like 1st.