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 a few opt-in extensions, and Reddit never added a lowered-type marker.

Markdown subscript syntax and where each form works
You wantWriteWhere it works
Water, body textH<sub>2</sub>OGitHub, GitLab, Obsidian, VS Code
Water, Pandoc sourceH~2~OPandoc, R Markdown, Hugo with extras
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}$. Math sets letters in italic, so for chemistry write $\mathrm{H_2O}$ to keep them upright.

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

The area is x².

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, misparses on old RedditCareful
^(like this)
How it looks on www.reddit.com

like this

Reddit's own compatibility notes say to avoid ^(...) when the raised text contains a link. In the Markdown editor these work as typed; the default Rich Text editor leaves the carets literal. 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

Hugo can use the same ^...^ and ~...~ forms once you enable the Goldmark extras superscript and subscript options (off by default). Do not paste these into a GitHub README: GitHub prints the carets as typed, and it reads single tildes as strikethrough. 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.

Unicode superscript and subscript characters to paste
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 are worse than literal: GitHub also accepts a single tilde as strikethrough, so H~2~O renders as H, a struck-through 2, then O.

Broken

^(two words)

Fixed

^two ^words
The parenthesized Reddit form works on www.reddit.com but old Reddit misparses it, and Reddit's own guidance is to avoid it when the raised text contains a link. Put a caret in front of each word instead.

Broken

E = mc<sup>2</sup>  (in Hugo)

Fixed

E = mc^2^  (Goldmark extras on)
Hugo drops raw HTML by default, so the tags vanish and you get E = mc2. Either set markup.goldmark.renderer.unsafe = true, or enable the superscript and subscript Goldmark extras and use ^...^ and ~...~.

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

Superscript and subscript syntax 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 (2 is struck through)
-# textDiscord subtextNo

Platform Support

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

Superscript and subscript support by platform
PlatformSupported?Notes
GitHubYes<sup> and <sub> are on the HTML allowlist. $x^2$ and $H_2O$ also work in math mode.
GitLabYesHTML tags work. GitLab's docs say the old Redcarpet caret syntax (x^2) is not supported. Math works too.
VS Code previewYesThe built-in preview passes <sup> and <sub> through and renders $x^2$ math with KaTeX.
ObsidianYesReading view renders the HTML tags. MathJax $x^{2}$ and $H_{2}O$ work for formulas.
Pandoc / R Markdown / QuartoYesNative extensions: ^super^ and ~sub~. Spaces inside must be backslash-escaped.
HugoPartialRaw HTML is dropped by default (unsafe = false). Enable it, or turn on Goldmark extras for 1^st^ and H~2~O.
RedditPartialCaret superscript only (^word or ^(words)). No subscript. HTML is not rendered.
NotionNoNo superscript formatting and no HTML. Use an inline equation (/equation) with ^ and _, or a Unicode character.
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?

A lone caret only works on Reddit, placed immediately before the characters you want raised. Pandoc, R Markdown, and Hugo's optional Goldmark extras need a closing caret too: x^2^. 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. Reddit does not render HTML in posts or 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.

Why does <sup> show up as plain text in Hugo?

Hugo's Markdown renderer, Goldmark, omits raw HTML unless markup.goldmark.renderer.unsafe is set to true, so <sup>2</sup> loses its tags and renders as a plain 2. Either enable unsafe for content you control, or enable the Goldmark extras superscript and subscript and write 1^st^ and H~2~O. Enabling subscript means turning off the strikethrough extension, which also uses tildes.

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.