FontBackgroundColorPlugin: Control background color with background-color styleFontColorPlugin: Control font color with color styleFontFamilyPlugin: Change font family using inline elements with font-family styleFontSizePlugin: Control font size with CSS class or font-size styleThe fastest way to add font styling functionality is with the FontKit, which includes pre-configured font plugins with their Plate UI components.
'use client';
import {
FontBackgroundColorPlugin,
FontColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
} from 'platejs/react';
export const FontKit = [
FontColorPlugin,
FontBackgroundColorPlugin,
FontSizePlugin,
FontFamilyPlugin,
];'use client';
import {
FontBackgroundColorPlugin,
FontColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
} from 'platejs/react';
export const FontKit = [
FontColorPlugin,
FontBackgroundColorPlugin,
FontSizePlugin,
FontFamilyPlugin,
];FontColorPlugin, FontBackgroundColorPlugin, FontSizePlugin, FontFamilyPlugin) with sensible defaults.Add the kit to your plugins:
import { createEditor } from "platejs/react";
import { FontKit } from "@/components/editor/font";
const editor = createEditor({
plugins: [
// ...otherPlugins,
...FontKit,
],
});import { createEditor } from "platejs/react";
import { FontKit } from "@/components/editor/font";
const editor = createEditor
Include the font plugins in your Plate plugins array when creating the editor.
import {
FontBackgroundColorPlugin,
FontColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
} from "platejs/react";
import { createEditor } from "platejs/react";
const editor = createEditor({
plugins: [
// ...otherPlugins,
FontColorPlugin,
FontBackgroundColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
],
});import {
FontBackgroundColorPlugin,
FontColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
} from "platejs/react";
import { createEditor } from "platejs/react";
const editor = createEditor({
plugins: [
// ...otherPlugins,
FontColorPlugin,
FontBackgroundColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
],
});Font plugins register string-valued text marks, so they follow the selected
text instead of a block target list. Every stored value renders, so a pasted
color: black draws black in every theme. HTML parsers read font styles
directly onto text properties; block target injection does not constrain text
marks.
When you paste or parse HTML copied from Google Docs, the font plugins skip the
default text style Docs writes on every run: black text, 11pt, Arial and a
transparent background. With HeadingPlugin, a run in a heading skips its
level's default size in place of 11pt: 20pt, 16pt, 14pt, 12pt, 11pt
and 11pt for Heading 1 to 6. It also skips the grey of Heading 3, #434343,
and of Heading 4 to 6, #666666, so the heading takes your editor's own
heading size and color. This holds wherever the heading lands, such as in a
list item that pastes as a list paragraph because the targetPlugins of
ListPlugin leave out headings. Without HeadingPlugin, a heading pastes as a
paragraph and keeps its level's size and grey, apart from the 11pt that
Heading 5 and 6 share with body text. Text that Docs copies without its heading
tag keeps that size and grey too. The text color stays on a highlight when the
editor has FontBackgroundColorPlugin, and in a shaded table cell when it has
, because the author read the text against that background. A
color, size, font or highlight other than those defaults is kept.
Font weight is not a font mark. Bold owns it, so a pasted
font-weight of 600 or more stores bold.
You can add FontColorToolbarButton and FontSizeToolbarButton to your Toolbar to control font color and size.
Plugin for font background color formatting. Applies background-color style to selected text.
Plugin for font color formatting. Applies color style to selected text.
Plugin for font family formatting. Applies font-family style to selected text.
Plugin for font size formatting. Applies font-size style to selected text.
Set the font background color mark on the selected text.
Set the font color mark on the selected text.
Set the font family mark on the selected text.
Set the font size mark on the selected text.
TablePlugin