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 the Plate UI setup. It targets headings, paragraphs, images, and media embeds.
'use client';
import { TextAlignPlugin } from '@platejs/basic-styles/react';
import { PLUGINS } from 'platejs';
export const AlignKit = [
TextAlignPlugin.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,
],
}),
];'use client';
import { TextAlignPlugin } from '@platejs/basic-styles/react';
import { PLUGINS } from 'platejs';
export const AlignKit = [
TextAlignPlugin.configure({
inject: {
nodeProps: {
defaultNodeValue: 'start',
styleKey: 'textAlign',
validNodeValues: ['start', 'left', 'center', 'right', 'end', 'justify'],
},
},
targetPlugins: [
PLUGINS.heading,
PLUGINS.paragraph,
PLUGINS.image,
import { createPlateEditor } from "platejs/react";
import { AlignKit } from "@/components/editor/align";
export const editor = createPlateEditor({
plugins: [...AlignKit],
});import { createPlateEditor } from "platejs/react";
import { AlignKit } from "@/components/editor/align";
export const editor = createPlateEditor({
plugins: [
AlignToolbarButton 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 { TextAlignPlugin } from "@platejs/basic-styles/react";
import { PLUGINS } from "platejs";
import { createPlateEditor } from "platejs/react";
export const editor = createPlateEditor({
plugins: [
TextAlignPlugin.configure({
targetPlugins: [
PLUGINS.heading, PLUGINS.heading, PLUGINS.heading, PLUGINS.heading, PLUGINS.heading, PLUGINS.heading,
PLUGINS.paragraph,
],
inject: {
nodeProps: {
defaultNodeValue: "start",
styleKey: "textAlign",
validNodeValues: [
"start",
import { TextAlignPlugin } from "@platejs/basic-styles/react";
import { PLUGINS } from "platejs";
import { createPlateEditor } from "platejs/react";
export const editor = createPlateEditor({
plugins: [
TextAlignPlugin.configure({
targetPlugins: [
PLUGINS.heading, PLUGINS.heading, PLUGINS.heading, PLUGINS.heading, PLUGINS.heading, PLUGINS.heading,
PLUGINS.paragraph,
],
inject: {
nodeProps: {
defaultNodeValue: "start",
styleKey: "textAlign",
validNodeValues: [
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/basic-styles | Headless plugin that stores alignment, injects block props, and parses HTML text-align styles. |
TextAlignPlugin | @platejs/basic-styles/react | React wrapper around BaseTextAlignPlugin. |
editor.update.textAlign.set | @platejs/basic-styles | Bound update method exposed by the plugin. |
BaseAlignKit | Registry kit | Static/headless setup for headings, paragraphs, images, and media embeds. |
AlignKit | Registry kit | React setup plus toolbar dependency. |
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/basic-styles/react | React alignment plugin. |
BaseTextAlignPlugin | @platejs/basic-styles | Headless alignment plugin. |
editor.update.textAlign.set(value, options?) | @platejs/basic-styles | Sets or clears alignment on matching blocks. |
tx.textAlign.set(value, options?) | @platejs/basic-styles | Transaction form for a larger atomic update. |
| Option | Surface | Use |
|---|---|---|
targetPlugins | TextAlignPlugin | Element plugin descriptors or dynamic names whose schema can keep textAlign; injection is derived from this list. |
inject.nodeProps.defaultNodeValue | TextAlignPlugin | Value that clears the stored property when selected. |
inject.nodeProps.styleKey | TextAlignPlugin | CSS property used for rendering. |
inject.nodeProps.validNodeValues | Registry toolbar | Values exposed to alignment UI. |
options | editor.update.textAlign.set | Plite node update options for the target range and matcher. |