Plate
PlateEditorsTemplates
GitHub16kGitHub
DiscordDiscord
    • Stream
    • Copilot
  • Comments
  • Discussion
  • Suggestions
    • Basic Blocks
      • Blockquote
      • Heading
      • Horizontal Rule
    • Callout
    • Code Block
    • Column
    • Date
    • Equation
    • Link
    • Media
    • MentionElement
    • Table
    • Table of Contents
    • Footnote
    • Details
  • Marks
    • Bold
    • Italic
    • Underline
    • Code
    • Highlight
    • Keyboard Input
    • Strikethrough
    • Subscript
    • Superscript
      • Font
      • Line Height
      • Text Align
    • Indent
    • List
      • Exit Break
      • Single Block
      • Trailing Block
    • Autoformat
    • Block Menu
    • Block Placeholder
    • Combobox
      • Emoji
      • MentionElement
      • Slash Command
    • Drag & Drop
    • Navigation Feedback
    • Linting
    • Tabbable
    • Toolbar
    • Yjs
    • Multi SelectEditor
    • DOCX
    • HTML
    • Markdown

Line Height

PreviousNext

Set block line height.

Line Height DemoLine Height Toolbar Button

LineHeightPlugin stores line height on blocks as a positive number in a lineHeight property. A block without one follows the theme's line height.

Loading…
FontText Align

On This Page

FeaturesKit usageAdd the kitAdd the toolbar controlManual usageInstall packageAdd the pluginSet line heightOwnershipBehaviorHTMLAPI ReferenceOptions
Build your editor
Production-ready AI template and reusable components.
Get all-access

Features

  • Block-level lineHeight storage as a positive number.
  • HTML line-height parsing into a line-height multiplier.
  • Configurable target block types.
  • Bound editor.update.lineHeight.set and editor.update.lineHeight.clear methods.
  • Registry dropdown toolbar with line-height presets and a Default item.
Report an issue

Kit usage

Add the kit

Use LineHeightKit for live and static Plate UI setups. The server-safe kit targets paragraphs and all heading levels.

import { BaseLineHeightPlugin, PLUGINS } from 'platejs';
 
export const LineHeightKit = [
  BaseLineHeightPlugin.configure({
    targetPlugins: [PLUGINS.heading, PLUGINS.paragraph],
  }),
] as const;
import { BaseLineHeightPlugin, PLUGINS } from 'platejs';
 
export const LineHeightKit = [
  BaseLineHeightPlugin.configure({
    targetPlugins: [PLUGINS.heading, PLUGINS.paragraph],
  }),
] as const;
import { createEditor } from "platejs/react";
 
import { LineHeightKit } from "@/components/editor/line-height";
 
export const editor = createEditor({
  plugins: [...LineHeightKit],
});
import { createEditor } from "platejs/react";
 
import { LineHeightKit } from "@/components/editor/line-height";
 
export const editor = createEditor({

Add the toolbar control

Install LineHeightToolbarButton separately when the editor needs a line-height control.

pnpm dlx shadcn@latest add @plate/line-height-toolbar-button
pnpm dlx shadcn@latest add @plate/line-height-toolbar-button

The dropdown lists the presets 1, 1.2, 1.5, 2, and 3 from its own file, plus a Default item that clears the value. Blocks with no line height check Default, and a selection with mixed values checks nothing.

import { LineHeightToolbarButton } from "@/components/editor/line-height-toolbar-button";
 
export function LineHeightControls() {
  return <LineHeightToolbarButton />;
}
import { LineHeightToolbarButton } from "@/components/editor/line-height-toolbar-button";
 
export function LineHeightControls() {
  return <LineHeightToolbarButton />;
}

Manual usage

Install package

pnpm add platejs
pnpm add platejs

Add the plugin

Configure the blocks that can store line height.

import { BaseLineHeightPlugin, PLUGINS } from "platejs";
import { createEditor } from "platejs/react";
 
export const editor = createEditor({
  plugins: [
    BaseLineHeightPlugin.configure({
      targetPlugins: [
        PLUGINS.heading,
        PLUGINS.paragraph,
      ],
    }),
  ],
});
import { BaseLineHeightPlugin, PLUGINS } from "platejs";
import { createEditor } from "platejs/react";
 
export const editor = createEditor({
  plugins: [
    BaseLineHeightPlugin.configure({
      targetPlugins: [
        PLUGINS.heading,
        PLUGINS.paragraph,
      ],
    }),
  ],
});

Set line height

Use the bound update methods. clear removes the property, so the block follows the theme.

editor.update.lineHeight.set(2);
editor.update.lineHeight.clear({ at: [] });
editor.update.lineHeight.set(2);
editor.update.lineHeight.clear({ at: [] });

Ownership

SurfaceOwnerWhat It Does
BaseLineHeightPluginplatejsHeadless plugin that stores lineHeight, injects block props, and parses HTML line-height styles.
LineHeightPluginplatejs/reactReact wrapper around BaseLineHeightPlugin.
editor.update.lineHeight.setplatejsBound update method that saves a line height.
editor.update.lineHeight.clearplatejsBound update method that removes a line height.
LineHeightKitRegistry kitServer-safe setup shared by live and static kits.
LineHeightToolbarButtonRegistry UIDropdown that writes presets through lineHeight.set and Default through lineHeight.clear.

The package owns line-height storage and parsing. The registry owns the dropdown UI and its presets.

Behavior

BehaviorSource
Plugin namePLUGINS.lineHeight
Stored propertylineHeight
Stored valueA positive finite number.
Default target plugins[BaseParagraphPlugin]
Registry target plugins[PLUGINS.heading, PLUGINS.paragraph]
RenderingEvery stored value renders as CSS line-height.
HTML parserParses element.style.lineHeight, as HTML shows.
Setting a valueSets { lineHeight: value } on matching blocks.
ClearingUnsets lineHeight on matching blocks.
Non-target blocksAre ignored by lineHeight.set and lineHeight.clear.

HTML

targetPlugins is the schema placement truth. The plugin derives its render and HTML-parser injection targets from the same list. When pasted HTML contains an inline line-height style on a target block, Plate parses it into a multiplier and stores that number on the block.

<p style="line-height: 150%">Readable spacing</p>
<p style="line-height: 150%">Readable spacing</p>
Pasted CSS line heightSaved valueDiagnostic
1.5, 150%, 1.5em1.5none
107% from Word1.07none
normal, another keyword, calc() or var()nothing, so the block follows the themea dropped-property warning
24px, 18pt, 1.5remnothing, so the block follows the themea dropped-property warning
zeronothinga dropped-property warning
a negative number or other invalid CSSnothingnone in a browser, a dropped-property warning on the server

A browser drops a negative number or other invalid CSS before Plate reads the style, so that paste saves nothing and warns about nothing. platejs/html/server keeps those declarations, so a server parse warns about them too.

The warning arrives with the paste's other HTML diagnostics.

API Reference

APIPackageUse
LineHeightPluginplatejs/reactReact line-height plugin.
BaseLineHeightPluginplatejsHeadless line-height plugin.
editor.update.lineHeight.set(value, options?)platejsSets line height on matching blocks.
editor.update.lineHeight.clear(options?)platejsRemoves line height from matching blocks.
tx.lineHeight.set(value, options?)platejsTransaction form for a larger atomic update.
tx.lineHeight.clear(options?)platejsTransaction form of clear.

Options

OptionSurfaceUse
targetPluginsBaseLineHeightPluginElement plugin descriptors or dynamic names whose nodes can keep lineHeight; injection is derived from this list.
optionseditor.update.lineHeight.set, editor.update.lineHeight.clearPlate node update options for the target range and matcher.
plugins: [...LineHeightKit],
});