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.

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 { Editor, Document, Paragraph, Text, Subscript, defaultIcons } from '@domternal/core';
import '@domternal/theme';
const editorEl = document.getElementById('editor')!;
// Toolbar with subscript button
const toolbar = document.createElement('div');
toolbar.className = 'dm-toolbar';
toolbar.innerHTML = `<div class="dm-toolbar-group">
<button class="dm-toolbar-button" data-mark="subscript">${defaultIcons.textSubscript}</button>
</div>`;
editorEl.before(toolbar);
const editor = new Editor({
element: editorEl,
extensions: [Document, Paragraph, Text, Subscript],
content: '<p>Water is H<sub>2</sub>O.</p>',
});
toolbar.addEventListener('click', (e) => {
const btn = (e.target as Element).closest<HTMLButtonElement>('[data-mark]');
if (btn) editor.chain().focus().toggleSubscript().run();
});
PropertyValue
ProseMirror namesubscript
TypeMark
HTML tag<sub>
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