Skip to content

Superscript

The Superscript mark applies superscript formatting to text. It renders as <sup> and parses <sup> tags and CSS vertical-align: super. Superscript and Subscript are mutually exclusive: applying one automatically removes the other. Not included in StarterKit - must be added separately.

Use Superscript when you need:

  • Exponents and ordinals (x², 1ˢᵗ, 2ⁿᵈ)
  • Trademark and copyright markers (™, ®)
  • Footnote markers when rendered numerically

Notes:

  • Superscript and Subscript are mutually exclusive: applying one removes the other on the same range
  • Not in StarterKit; add explicitly when scientific or legal content is expected

Select text and apply superscript with buttons or keyboard shortcut (Cmd+. / Ctrl+.).

With the default theme enabled. Click the superscript toolbar button or use Cmd+. / Ctrl+..

Click to try it out

Superscript is not included in StarterKit. Add it separately:

import { Document, Paragraph, Text, Superscript } from '@domternal/core';
import { DomternalEditor, DomternalToolbar } from '@domternal/vanilla';
import '@domternal/theme';
const editorEl = document.getElementById('editor')!;
const toolbarEl = document.createElement('div');
editorEl.before(toolbarEl);
const dm = new DomternalEditor(editorEl, {
extensions: [Document, Paragraph, Text, Superscript],
content: '<p>Einstein\'s equation: E=mc<sup>2</sup>.</p>',
});
new DomternalToolbar(toolbarEl, { editor: dm.editor });
PropertyValue
ProseMirror namesuperscript
TypeMark
HTML tag<sup>
Groupformatting
Excludes'' (nothing: sub/superscript mutual exclusion lives in the commands, see below)

The two rows work in opposite directions. Superscript excludes nothing itself, but it carries the formatting group, and inline Code declares excludes: 'formatting', so code strips superscript from the range it is applied to and <code><sup>2</sup></code> parses as plain code. See Excluding third-party marks.

SourceCondition
<sup>Always
CSS vertical-alignValue is super
OptionTypeDefaultDescription
HTMLAttributesRecord<string, unknown>{}Custom HTML attributes added to the rendered <sup> element
import { Superscript } from '@domternal/core';
const CustomSuperscript = Superscript.configure({
HTMLAttributes: { class: 'my-superscript' },
});

Applies superscript formatting to the current selection. Automatically removes subscript from the selection first.

editor.commands.setSuperscript();

Removes superscript formatting from the current selection.

editor.commands.unsetSuperscript();

Toggles superscript formatting on the current selection. Automatically removes subscript before applying superscript.

editor.commands.toggleSuperscript();
// With chaining
editor.chain().focus().toggleSuperscript().run();
KeyAction
Mod-.Toggle superscript (toggleSuperscript)

Mod is Cmd on macOS and Ctrl on Windows/Linux.

Superscript has no input rules. Use the keyboard shortcut or toolbar button to apply formatting.

Superscript registers a button in the toolbar with the name superscript in group format at priority 130.

ItemTypeCommandIconShortcutActive when
SuperscriptbuttontoggleSuperscripttextSuperscriptMod-.Superscript mark is active on selection
import { Superscript } from '@domternal/core';
import type { SuperscriptOptions } from '@domternal/core';
ExportTypeDescription
SuperscriptMark extensionThe superscript mark extension
SuperscriptOptionsTypeScript typeOptions for Superscript.configure()

@domternal/core - Superscript.ts

  • Subscript - subscript text rendered as <sub>
  • Bold - strong emphasis with Cmd+B and **markdown**
  • Italic - inline emphasis with Cmd+I and *markdown*
  • Clear Formatting - removes all inline marks from selection