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.
E = mc<sup>2</sup>E = mc2
H<sub>2</sub>O and CO<sub>2</sub>H2O and CO2
The ion is SO<sub>4</sub><sup>2-</sup>.The ion is SO42-.
See footnote <sup>1</sup> and the formula H<sub>2</sub>O.See footnote 1 and the formula H2O.
<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.
| You want | Write | Where it works |
|---|---|---|
| Water, body text | H<sub>2</sub>O | GitHub, GitLab, Obsidian, VS Code |
| Water, Pandoc source | H~2~O | Pandoc, R Markdown, Hugo with extras |
| Water, a formula | $H_2O$ | GitHub math, Obsidian MathJax |
| Water, on Reddit | No subscript. Write H2O or use ₂. |
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.
The area is $x^2$.The area is x².
Water is $H_2O$.Water is H₂O.
$$a^2 + b^2 = c^2$$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.
E = mc^2E = mc2
^like ^thislike this
^(like this)like this
^(...) 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.
2^10^ is 1024.210 is 1024.
H~2~O is a liquid.H2O is a liquid.
n^th\ term^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.
| Meaning | Paste |
|---|---|
| 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^2Fixed
x<sup>2</sup> + y<sup>2</sup> = z<sup>2</sup>Broken
H~2~OFixed
H<sub>2</sub>OBroken
^(two words)Fixed
^two ^wordsBroken
E = mc<sup>2</sup> (in Hugo)Fixed
E = mc^2^ (Goldmark extras on)Broken
-# smaller textFixed
Paste ² or write it in UnicodeQuick Reference
| Syntax | Result | Works on GitHub? |
|---|---|---|
| <sup>2</sup> | Raised 2 | Yes |
| <sub>2</sub> | Lowered 2 | Yes |
| $x^2$ | Math exponent | Yes (math font) |
| $H_2O$ | Math subscript | Yes (math font) |
| ^word | Reddit superscript | No |
| 2^10^ | Pandoc superscript | No |
| H~2~O | Pandoc subscript | No (2 is struck through) |
| -# text | Discord subtext | No |
Platform Support
Support splits on whether the renderer allows HTML, and whether it invented its own marker.
| Platform | Supported? | Notes |
|---|---|---|
| GitHub | Yes | <sup> and <sub> are on the HTML allowlist. $x^2$ and $H_2O$ also work in math mode. |
| GitLab | Yes | HTML tags work. GitLab's docs say the old Redcarpet caret syntax (x^2) is not supported. Math works too. |
| VS Code preview | Yes | The built-in preview passes <sup> and <sub> through and renders $x^2$ math with KaTeX. |
| Obsidian | Yes | Reading view renders the HTML tags. MathJax $x^{2}$ and $H_{2}O$ work for formulas. |
| Pandoc / R Markdown / Quarto | Yes | Native extensions: ^super^ and ~sub~. Spaces inside must be backslash-escaped. |
| Hugo | Partial | Raw HTML is dropped by default (unsafe = false). Enable it, or turn on Goldmark extras for 1^st^ and H~2~O. |
| Partial | Caret superscript only (^word or ^(words)). No subscript. HTML is not rendered. | |
| Notion | No | No superscript formatting and no HTML. Use an inline equation (/equation) with ^ and _, or a Unicode character. |
| Discord | No | No HTML, no caret syntax. -# is subtext, not subscript. Unicode only. |
| Slack | No | mrkdwn has no raised or lowered type and strips HTML. |
| CommonMark / GFM | Partial | No 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.