Skip to content

Hard Break

The HardBreak node provides an inline line break (<br>). Unlike pressing Enter (which creates a new paragraph), a hard break inserts a line break within the same paragraph. It also provides a command for inserting non-breaking spaces.

HardBreak is included in StarterKit. If you are building a custom setup without StarterKit, add it manually:

import { Editor, Document, Text, Paragraph, HardBreak } from '@domternal/core';
const editor = new Editor({
element: document.getElementById('editor')!,
extensions: [Document, Text, Paragraph, HardBreak],
content: '<p>First line<br>Second line in the same paragraph</p>',
});
PropertyValue
ProseMirror namehardBreak
TypeNode
Groupinline
InlineYes
SelectableNo
ContentNone (leaf node)
HTML tag<br>

HardBreak is an inline leaf node. It sits inside text content alongside text nodes and marks. It is not selectable, so the cursor skips over it rather than selecting it as a node.

OptionTypeDefaultDescription
HTMLAttributesRecord<string, unknown>{}HTML attributes added to the <br> element
import { HardBreak } from '@domternal/core';
const CustomHardBreak = HardBreak.configure({
HTMLAttributes: { class: 'my-break' },
});
CommandDescription
setHardBreak()Insert a hard break (<br>) at the current cursor position
insertNbsp()Insert a non-breaking space (&nbsp;) at the current cursor position
// Insert a line break
editor.commands.setHardBreak();
// Insert a non-breaking space
editor.commands.insertNbsp();
// With chaining
editor.chain().focus().setHardBreak().run();

setHardBreak inserts a <br> node at the cursor position. insertNbsp inserts a Unicode non-breaking space character (U+00A0), which prevents the browser from collapsing whitespace at that position.

ShortcutCommand
Mod-EntersetHardBreak()
Shift-EntersetHardBreak()
Mod-Shift-SpaceinsertNbsp()

HardBreak registers a button in the toolbar with the name hardBreak in group insert at priority 50.

ItemCommandIconShortcut
Hard BreaksetHardBreaklinkBreakShift-Enter
{
"type": "hardBreak"
}

A paragraph with a hard break:

{
"type": "paragraph",
"content": [
{ "type": "text", "text": "First line" },
{ "type": "hardBreak" },
{ "type": "text", "text": "Second line" }
]
}

@domternal/core - HardBreak.ts