Skip to content

Underline

The Underline mark applies underline formatting to text. It renders as <u> and parses <u> tags and CSS text-decoration: underline. Included in StarterKit by default.

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

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

Click to try it out

Underline is included in StarterKit, so it works out of the box. To use it standalone:

import { Editor, Document, Paragraph, Text, Underline, defaultIcons } from '@domternal/core';
import '@domternal/theme';
const editorEl = document.getElementById('editor')!;
// Toolbar
const toolbar = document.createElement('div');
toolbar.className = 'dm-toolbar';
toolbar.innerHTML = `<div class="dm-toolbar-group">
<button class="dm-toolbar-button" data-mark="underline">${defaultIcons.textUnderline}</button>
</div>`;
editorEl.before(toolbar);
// Editor
const editor = new Editor({
element: editorEl,
extensions: [Document, Paragraph, Text, Underline],
content: '<p>This is <u>underlined</u> text.</p>',
});
// Toggle underline on click
toolbar.addEventListener('click', (e) => {
const btn = (e.target as Element).closest<HTMLButtonElement>('[data-mark]');
if (btn) editor.chain().focus().toggleUnderline().run();
});

To disable Underline in StarterKit:

StarterKit.configure({ underline: false })
PropertyValue
ProseMirror nameunderline
TypeMark
HTML tag<u>
SourceCondition
<u>Always
CSS text-decorationValue includes underline

The text-decoration style check uses includes('underline'), so compound values like underline dotted are also matched.

OptionTypeDefaultDescription
HTMLAttributesRecord<string, unknown>{}Custom HTML attributes added to the rendered <u> element
import { Underline } from '@domternal/core';
const CustomUnderline = Underline.configure({
HTMLAttributes: { class: 'my-underline' },
});

Applies underline formatting to the current selection.

editor.commands.setUnderline();

Removes underline formatting from the current selection.

editor.commands.unsetUnderline();

Toggles underline formatting on the current selection. Applies underline if not active, removes it if active.

editor.commands.toggleUnderline();
// With chaining
editor.chain().focus().toggleUnderline().run();
KeyAction
Mod-UToggle underline (toggleUnderline)

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

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

Underline registers a button in the toolbar with the name underline in group format at priority 180.

ItemTypeCommandIconShortcutActive when
UnderlinebuttontoggleUnderlinetextUnderlineMod-UUnderline mark is active on selection
import { Underline } from '@domternal/core';
import type { UnderlineOptions } from '@domternal/core';
ExportTypeDescription
UnderlineMark extensionThe underline mark extension
UnderlineOptionsTypeScript typeOptions for Underline.configure()

@domternal/core - Underline.ts