Markdown Subscript and Superscript: Syntax by Platform

September 11, 2026 · 7 min read

Markdown Subscript and Superscript: Syntax by Platform

A markdown subscript is written as H~2~O in Pandoc-style Markdown, and a superscript as x^2^. Neither works on GitHub, GitLab, or Obsidian, where the portable answer is HTML: H<sub>2</sub>O and x<sup>2</sup>. This guide gives the working syntax for each platform, plus the LaTeX and Unicode fallbacks.

Markdown Subscript Syntax: Three Ways to Write It

CommonMark has no syntax for subscript in Markdown or superscript at all. Every method you'll meet is an extension, HTML, or a different language borrowed for the job. There are three families, and knowing which one your renderer speaks saves you from pasting tildes that print literally.

Tilde and caret (Pandoc style). The Pandoc manual defines ~text~ for subscript and ^text^ for superscript under its subscript and superscript extensions. The text between the markers may not contain spaces or newlines; a space must be escaped as \ .

H~2~O is a liquid. 2^10^ is 1024. P~a\ cat~ has an escaped space.

Pandoc 3.8 renders that as H2O, 210, and Pa cat. Tools built on markdown-it get the same behaviour from the markdown-it-sub and markdown-it-sup plugins, which the plugin README says are based on the Pandoc definition.

HTML tags. <sub> and <sup> are ordinary inline HTML, so every renderer that passes HTML through shows them correctly.

H<sub>2</sub>O and E = mc<sup>2</sup> and the 25<sup>th</sup> anniversary

This renders as H2O, E = mc2, and 25th. It's the only form that works on GitHub, GitLab, Obsidian, and VS Code out of the box, which is why we prefer it for anything shared.

LaTeX inside math delimiters. Where a platform renders math, $ opens an inline equation and the LaTeX operators _ and ^ do the work: $H_2O$, $x^2$, $CO_2$. Wrap multi-character scripts in braces, as in $x^{10}$. The Markdown equation guide covers the rest of the math syntax.

Markdown Superscript and Subscript Support by Platform

Here's which of the three families each platform accepts. "HTML" means the <sub> and <sup> tags survive sanitisation, and "LaTeX" means $...$ math renders.

Platform~x~ / ^x^HTML <sub> <sup>LaTeX $_2$ $^2$
GitHubNo (single ~ is strikethrough)YesYes
GitLabNoYesYes (KaTeX)
ObsidianNoYesYes (MathJax)
VS Code previewNo without an extensionYesYes (KaTeX)
Jupyter notebooksNoYesYes (MathJax)
Pandoc / R Markdown / QuartoYesYesYes
NotionNoNoYes, in an inline equation
DiscordNoNoNo; Unicode only
SlackNoNoNo; Unicode only

The GitHub row deserves a closer look. GitHub's formatting docs list <sub> and <sup> as supported styling, and the GFM spec's strikethrough extension says struck text is wrapped in "a matching pair of one or two tildes". So H~2~O on GitHub is not a subscript. Per the spec it's an H, a struck-through 2, and an O. The Markdown strikethrough guide covers the tilde rules in full.

GitLab is explicit in its GitLab Flavored Markdown docs: the caret superscript syntax isn't supported, and the example it gives is H<sub>2</sub>O with HTML tags.

Obsidian's help pages list no sub or superscript markup, and the HTML page says notes are sanitised without listing every allowed tag. <sub> and <sup> are standard inline elements with no scripting risk, and Obsidian users on the community forums confirm they render. The Obsidian cheat sheet covers the rest of its syntax. If you need certainty for a particular vault, paste the demo below and check.

How Do You Use Superscript in Markdown?

Pick the method by destination, in this order.

  1. Writing for GitHub, GitLab, a README, or a wiki: use <sup>2</sup>. It's verbose but it renders everywhere HTML is allowed.
  2. Writing math or chemistry: use $x^2$ and $H_2O$ inside math delimiters where the platform supports them. Nested scripts like $x^{y^2}$ work.
  3. Writing for Pandoc, R Markdown, or Quarto output: use 2^10^. It converts cleanly to HTML, DOCX, and PDF.
  4. Writing for a chat box with no markup (Discord, Slack, SMS): paste a Unicode character. through exist as superscripts and through as subscripts, so and CO₂ survive anywhere text does.

The Unicode route has a real limitation: only digits, a handful of letters, and the plus, minus, and equals signs exist as precomposed characters. There's no complete superscript uppercase set, so E = mc² works but a superscript TM needs the symbol or HTML.

Try Markdown Subscript in the Editor

The demo puts all three families side by side. Watch which lines render as scripts and which print their markers literally.

Subscript and superscript

HTML tags (portable):
H2O, CO2, E = mc2, 25th

LaTeX in math delimiters:
H2OH_2O, x2x^2, x10x^{10}, CO2CO_2, aija_{ij}

Pandoc tilde and caret (renderer-dependent):
H2O and x^2^

Unicode characters (work anywhere):
H₂O, x², CO₂, m³

The tilde trap:
Single tildes on GitHub: 2 is strikethrough, not subscript

50 words400 characters16 lines
Markdown

The Markdown to HTML converter shows the generated tags, so you can confirm whether a line became <sub> or stayed plain text before you paste it somewhere that matters.

Jupyter, Obsidian, and VS Code: Where LaTeX Wins

On three platforms that people search for most, the math route is the cleanest choice for subscripts and superscripts.

Jupyter. Markdown cells accept arbitrary HTML and render LaTeX through MathJax, per the Jupyter Notebook docs. So H<sub>2</sub>O and $H_2O$ both work. For a chemistry or physics notebook, the math version looks consistent with your equations. The Jupyter Markdown cheat sheet has the full cell syntax.

Obsidian. Both HTML tags and $...$ math render in Reading view. The tilde and caret forms don't, which matches what Obsidian users report. If you write formulas, $x^2$ also gets MathJax typography.

VS Code. The built-in preview uses markdown-it without the sub and sup plugins, so ~2~ prints literally. HTML tags render, and the preview renders $...$ math with KaTeX by default. Marketplace extensions add the Pandoc tilde and caret syntax if you want it.

Common Markdown Subscript Mistakes

Pasting ~2~ into a GitHub README. You get a struck-through 2 because the GFM spec treats one tilde as strikethrough. Replace it with <sub>2</sub>.

Putting a space inside Pandoc markers. x^hello world^ renders as plain text with carets. Pandoc requires x^hello\ world^, or use HTML for phrases.

Forgetting braces in LaTeX. $x^10$ renders as x¹ followed by a normal 0, because ^ binds to one character. Write $x^{10}$.

Using ^ and _ outside math. In plain prose, ^ is just a caret and _word_ is italic. The underscore route only works between dollar signs on a platform that renders math.

Subscript and Superscript FAQ

The right markdown subscript depends on the renderer: HTML tags are the portable choice, tildes and carets belong to Pandoc, and LaTeX gives the best typography wherever math renders. Test the three families in the editor before you paste them into a README, a notebook, or a note, and reach for Unicode only where no markup is allowed.