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.

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 { Editor, Document, Paragraph, Text, Superscript, defaultIcons } from '@domternal/core';
import '@domternal/theme';
const editorEl = document.getElementById('editor')!;
// Toolbar with superscript button
const toolbar = document.createElement('div');
toolbar.className = 'dm-toolbar';
toolbar.innerHTML = `<div class="dm-toolbar-group">
<button class="dm-toolbar-button" data-mark="superscript">${defaultIcons.textSuperscript}</button>
</div>`;
editorEl.before(toolbar);
const editor = new Editor({
element: editorEl,
extensions: [Document, Paragraph, Text, Superscript],
content: '<p>Einstein\'s equation: E=mc<sup>2</sup>.</p>',
});
toolbar.addEventListener('click', (e) => {
const btn = (e.target as Element).closest<HTMLButtonElement>('[data-mark]');
if (btn) editor.chain().focus().toggleSuperscript().run();
});
PropertyValue
ProseMirror namesuperscript
TypeMark
HTML tag<sup>
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