Skip to content

Text Style

The TextStyle mark is a carrier mark that wraps text in a <span> element. It has no visual output on its own - it serves as a container for other extensions (TextColor, FontFamily, FontSize, Highlight) that inject CSS attributes into it via addGlobalAttributes. Not included in StarterKit - must be added separately.

TextStyle is not included in StarterKit. Add it when using TextColor, FontFamily, FontSize, or Highlight:

import { Editor, Document, Paragraph, Text, TextStyle, TextColor } from '@domternal/core';
import '@domternal/theme';
const editor = new Editor({
element: document.getElementById('editor')!,
extensions: [Document, Paragraph, Text, TextStyle, TextColor],
});
PropertyValue
ProseMirror nametextStyle
TypeMark
HTML tag<span>
Priority101
SourceCondition
<span>Only when it has a style attribute
<mark>Always (used by Highlight extension)

Spans without style attributes are ignored to avoid wrapping plain <span> tags.

OptionTypeDefaultDescription
HTMLAttributesRecord<string, unknown>{}Custom HTML attributes added to the rendered <span> element

Applies a text style with specific attributes.

editor.commands.setTextStyle({ color: 'red' });

Removes the text style mark entirely.

editor.commands.removeTextStyle();

Removes text style marks that have no meaningful attributes (all attributes are null/undefined). This prevents empty <span> wrappers from remaining in the document.

editor.commands.removeEmptyTextStyle();

TextStyle has no keyboard shortcuts.

TextStyle has no input rules.

TextStyle has no toolbar items. The extensions that use it (TextColor, FontFamily, FontSize, Highlight) provide their own toolbar items.

TextStyle is a carrier mark. On its own, it renders an empty <span>. Other extensions add attributes to it:

// TextColor adds a 'color' style attribute
editor.commands.setTextColor('#ff0000');
// Renders: <span style="color: #ff0000">text</span>
// FontFamily adds a 'font-family' style attribute
editor.commands.setFontFamily('Georgia');
// Renders: <span style="font-family: Georgia">text</span>
// FontSize adds a 'font-size' style attribute
editor.commands.setFontSize('24px');
// Renders: <span style="font-size: 24px">text</span>

Multiple styles can be combined on a single <span>:

<span style="color: #ff0000; font-family: Georgia; font-size: 24px">styled text</span>
import { TextStyle } from '@domternal/core';
import type { TextStyleOptions } from '@domternal/core';
ExportTypeDescription
TextStyleMark extensionThe text style carrier mark
TextStyleOptionsTypeScript typeOptions for TextStyle.configure()

@domternal/core - TextStyle.ts