Plate
PlateEditorsCreateTemplates
GitHub16kGitHub
DiscordDiscord
    • Stream
    • Copilot
    • Prompt Editor
  • Comments
  • Discussion
  • Suggestions
    • Basic Blocks
      • Blockquote
      • Heading
      • Horizontal Rule
    • Board
    • Callout
    • Code Block
    • Column
    • Date
    • Equation
    • FieldExperimental
    • 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
      • Clear Formatting
      • Format Painter
    • 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

Font

PreviousNext

Provide extended formatting options for document content.

Font Color Toolbar ButtonFont Size Toolbar Button
Loading…
SuperscriptLine Height

On This Page

FeaturesPluginsKit usageInstallationAdd kitManual usageInstallationAdd pluginsFont marksAdd toolbar buttonPluginsFontBackgroundColorPluginFontColorPluginFontFamilyPluginFontSizePluginTransformseditor.update.backgroundColor.seteditor.update.color.seteditor.update.fontFamily.seteditor.update.fontSize.set
Build your editor
Production-ready AI template and reusable components.
Get all-access

Features

  • Apply font styling to selected text including size, family, color, and background color.
  • Supports custom font families, sizes, and colors.

Plugins

  • FontBackgroundColorPlugin: Control background color with background-color style
  • FontColorPlugin: Control font color with color style
  • FontFamilyPlugin: Change font family using inline elements with font-family style
  • FontSizePlugin: Control font size with CSS class or font-size style
Report an issue

Kit usage

Installation

The 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,
];
  • Includes all font plugins (FontColorPlugin, FontBackgroundColorPlugin, FontSizePlugin, FontFamilyPlugin) with sensible defaults.

Add kit

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




Manual usage

Installation

pnpm add platejs
pnpm add platejs

Add plugins

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 marks

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.

Add toolbar button

You can add FontColorToolbarButton and FontSizeToolbarButton to your Toolbar to control font color and size.

Plugins

FontBackgroundColorPlugin

Plugin for font background color formatting. Applies background-color style to selected text.

FontColorPlugin

Plugin for font color formatting. Applies color style to selected text.

FontFamilyPlugin

Plugin for font family formatting. Applies font-family style to selected text.

FontSizePlugin

Plugin for font size formatting. Applies font-size style to selected text.

Transforms

editor.update.backgroundColor.set

Set the font background color mark on the selected text.

Parameters

    The background color value to set (e.g., '#ff0000', 'red').

editor.update.color.set

Set the font color mark on the selected text.

Parameters

    The color value to set (e.g., '#0000ff', 'blue').

editor.update.fontFamily.set

Set the font family mark on the selected text.

Parameters

    The font family value to set (e.g., 'Arial', 'Times New Roman').

editor.update.fontSize.set

Set the font size mark on the selected text.

Parameters

    The font size value to set (e.g., '16px', '1.2em').

({
plugins: [
// ...otherPlugins,
...FontKit,
],
});
TablePlugin