Skip to content

Horizontal Rule

The HorizontalRule node provides a block-level thematic break (<hr>). It supports markdown-style input rules (---, ***, ___ + space) and a toolbar button for insertion.

Type ---, ***, or ___ followed by space at the start of a line to insert a horizontal rule. You can also use the toolbar button.

Click to try it out

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

import { Editor, Document, Text, Paragraph, HorizontalRule } from '@domternal/core';
const editor = new Editor({
element: document.getElementById('editor')!,
extensions: [Document, Text, Paragraph, HorizontalRule],
content: '<p>Above the rule</p><hr><p>Below the rule</p>',
});
PropertyValue
ProseMirror namehorizontalRule
TypeNode
Groupblock
ContentNone (leaf node)
HTML tag<hr>

HorizontalRule is a leaf node with no content. It cannot contain text or other nodes.

OptionTypeDefaultDescription
HTMLAttributesRecord<string, unknown>{}HTML attributes added to the <hr> element
import { HorizontalRule } from '@domternal/core';
const CustomHR = HorizontalRule.configure({
HTMLAttributes: { class: 'my-divider' },
});
CommandDescription
setHorizontalRule()Insert a horizontal rule at the current cursor position
// Insert a horizontal rule
editor.commands.setHorizontalRule();
// With chaining
editor.chain().focus().setHorizontalRule().run();

setHorizontalRule has two behaviors depending on context:

  1. Cursor in an empty paragraph: Replaces the empty paragraph with the horizontal rule and creates a new paragraph below it.
  2. Cursor in a non-empty block: Inserts the horizontal rule after the current block and creates a new paragraph below it.

In both cases, the cursor moves into the new paragraph after the rule. The command only works when the cursor is inside a textblock - it will not insert inside non-text contexts like table cell selections.

InputResult
--- + spaceHorizontal rule
*** + spaceHorizontal rule
___ + spaceHorizontal rule

Type the pattern at the start of a new line, then press space. The entire paragraph is replaced with a horizontal rule, and the cursor moves to the next block below.

The regex also matches —- + space (em dash + hyphen + space), which handles the case where the Typography extension converts -- to before you type the third -.

HorizontalRule registers a button in the toolbar with the name horizontalRule in group blocks at priority 130.

ItemCommandIcon
Horizontal RulesetHorizontalRuleminus
{
"type": "horizontalRule"
}

A document with a horizontal rule between two paragraphs:

{
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{ "type": "text", "text": "Above" }
]
},
{ "type": "horizontalRule" },
{
"type": "paragraph",
"content": [
{ "type": "text", "text": "Below" }
]
}
]
}

@domternal/core - HorizontalRule.ts