TextAlignPlugin stores block alignment in a textAlign property and renders it as CSS text-align. Setting the default start value removes the property from matching blocks.
Use AlignKit for live and static Plate UI setups. The server-safe kit targets headings, paragraphs, images, and media embeds.
import { BaseTextAlignPlugin, PLUGINS } from 'platejs';
export const AlignKit = [
BaseTextAlignPlugin.configure({
inject: {
nodeProps: {
defaultNodeValue: 'start',
styleKey: 'textAlign',
validNodeValues: ['start', 'left', 'center', 'right', 'end', 'justify'],
},
},
targetPlugins: [
PLUGINS.heading,
PLUGINS.paragraph,
PLUGINS.image,
PLUGINS.mediaEmbed,
PLUGINS.audio,
PLUGINS.video,
],
}),
] as const;import { BaseTextAlignPlugin, PLUGINS } from 'platejs';
export const AlignKit = [
BaseTextAlignPlugin.configure({
inject: {
nodeProps: {
defaultNodeValue: 'start',
styleKey: 'textAlign',
validNodeValues: ['start', 'left', 'center', 'right', 'end', 'justify'],
},
},
targetPlugins: [
PLUGINS.heading,
PLUGINS.paragraph,
PLUGINS.image,
PLUGINS.mediaEmbed,
PLUGINS.audio,
PLUGINS.video,
import { createEditor } from "platejs/react";
import { AlignKit } from "@/components/editor/align";
export const editor = createEditor({
plugins: [...AlignKit],
});import { createEditor } from "platejs/react";
import { AlignKit } from "@/components/editor/align";
export const editor = createEditor({
Install AlignToolbarButton separately when the editor needs alignment controls.
The dropdown shows left, center, right, and justify controls.
import { AlignToolbarButton } from "@/components/editor/align-toolbar-button";
export function AlignControls() {
return <AlignToolbarButton />;
}import { AlignToolbarButton } from "@/components/editor/align-toolbar-button";
export function AlignControls() {
return <AlignToolbarButton />;
}Configure the blocks that can store alignment.
import { BaseTextAlignPlugin, PLUGINS } from "platejs";
import { createEditor } from "platejs/react";
export const editor = createEditor({
plugins: [
BaseTextAlignPlugin.configure({
targetPlugins: [
PLUGINS.heading,
PLUGINS.paragraph,
],
inject: {
nodeProps: {
defaultNodeValue: "start",
styleKey: "textAlign",
validNodeValues: [
"start",
"left",
"center",
"right",
"end",
import { BaseTextAlignPlugin, PLUGINS } from "platejs";
import { createEditor } from "platejs/react";
export const editor = createEditor({
plugins: [
BaseTextAlignPlugin.configure({
targetPlugins: [
PLUGINS.heading,
PLUGINS.paragraph,
],
inject: {
nodeProps: {
defaultNodeValue: "start",
styleKey: "textAlign",
validNodeValues: [
"start",
"left",
"center",
"right",
"end",
Use the bound update method.
editor.update.textAlign.set("center");
editor.update.textAlign.set("start", { at: [] });editor.update.textAlign.set("center");
editor.update.textAlign.set("start", { at: [] });| Surface | Owner | What It Does |
|---|---|---|
BaseTextAlignPlugin | platejs | Headless plugin that stores alignment, injects block props, and parses HTML text-align styles. |
TextAlignPlugin | platejs/react | React wrapper around BaseTextAlignPlugin. |
editor.update.textAlign.set | platejs | Bound update method exposed by the plugin. |
AlignKit | Registry kit | Server-safe setup shared by live and static editors. |
AlignToolbarButton | Registry UI | Dropdown that writes alignment through textAlign.set. |
The package owns alignment storage and parsing. The registry owns the dropdown UI.
| Behavior | Source |
|---|---|
| Plugin name | PLUGINS.textAlign |
| Stored property | textAlign |
| Rendered CSS style | textAlign |
| Default target plugins | [BaseParagraphPlugin] |
| Registry target plugins | Headings, paragraphs, images, and media embeds |
| Default value | start |
| Valid values | start, left, center, right, end, justify |
| HTML parser | Reads element.style.textAlign. |
| Setting a custom value | Sets { textAlign: value } on matching blocks. |
Setting start | Unsets the stored alignment property. |
| Non-target blocks | Are ignored by textAlign.set. |
targetPlugins is the schema placement truth. The plugin derives
its render and HTML-parser injection targets from the same list. Pasted HTML
with a text-align style becomes a textAlign property on matching blocks.
<p style="text-align: center">Centered text</p><p style="text-align: center">Centered text</p>| API | Package | Use |
|---|---|---|
TextAlignPlugin | platejs/react | React alignment plugin. |
BaseTextAlignPlugin | platejs | Headless alignment plugin. |
editor.update.textAlign.set(value, options?) | platejs | Sets or clears alignment on matching blocks. |
tx.textAlign.set(value, options?) | platejs | Transaction form for a larger atomic update. |
| Option | Surface | Use |
|---|---|---|
targetPlugins | BaseTextAlignPlugin | Element plugin descriptors or dynamic names whose schema can keep textAlign; injection is derived from this list. |
inject.nodeProps.defaultNodeValue | BaseTextAlignPlugin | Value that clears the stored property when selected. |
inject.nodeProps.styleKey | BaseTextAlignPlugin | CSS property used for rendering. |
inject.nodeProps.validNodeValues | Registry toolbar | Values exposed to alignment UI. |
options | editor.update.textAlign.set | Plate node update options for the target range and matcher. |