Skip to content

Subscript

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

Use Subscript when you need:

  • Chemical formulas (H₂O, CO₂)
  • Mathematical notation (xₙ, aᵢ)
  • Footnote references when rendered numerically

Notes:

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

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

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

Click to try it out

Subscript is not included in StarterKit. Add it separately:

import { Document, Paragraph, Text, Subscript } 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, Subscript],
content: '<p>Water is H<sub>2</sub>O.</p>',
});
new DomternalToolbar(toolbarEl, { editor: dm.editor });
PropertyValue
ProseMirror namesubscript
TypeMark
HTML tag<sub>
Groupformatting
Excludes'' (nothing: sub/superscript mutual exclusion lives in the commands, see below)

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

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

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

editor.commands.setSubscript();

Removes subscript formatting from the current selection.

editor.commands.unsetSubscript();

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

editor.commands.toggleSubscript();
// With chaining
editor.chain().focus().toggleSubscript().run();
KeyAction
Mod-,Toggle subscript (toggleSubscript)

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

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

Subscript registers a button in the toolbar with the name subscript in group format at priority 140.

ItemTypeCommandIconShortcutActive when
SubscriptbuttontoggleSubscripttextSubscriptMod-,Subscript mark is active on selection
import { Subscript } from '@domternal/core';
import type { SubscriptOptions } from '@domternal/core';
ExportTypeDescription
SubscriptMark extensionThe subscript mark extension
SubscriptOptionsTypeScript typeOptions for Subscript.configure()

@domternal/core - Subscript.ts

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