--- title: Lexical Overview label: Overview order: 10 desc: Built by Meta, Lexical is an incredibly powerful rich text editor, and it works beautifully within Payload. keywords: lexical, rich text, editor, headless cms --- One of Payload's goals is to build the best rich text editor experience that we possibly can. We want to combine the beauty and polish of the Medium editing experience with the strength and features of the Notion editor - all in one place. Classically, we've used SlateJS to work toward this goal, but building custom elements into Slate has proven to be more difficult than we'd like, and we've been keeping our options open. Lexical is extremely impressive and trivializes a lot of the hard parts of building new elements into a rich text editor. It has a few distinct advantages over Slate, including the following: 1. A "/" menu, which allows editors to easily add new elements while never leaving their keyboard 1. A "hover" toolbar that pops up if you select text 1. It supports Payload blocks natively, directly within your rich text editor 1. Custom elements, called "features", are much easier to build in Lexical vs. Slate To use the Lexical editor, first you need to install it: ``` npm install @payloadcms/richtext-lexical ``` Once you have it installed, you can pass it to your top-level Payload Config as follows: ```ts import { buildConfig } from 'payload' import { lexicalEditor } from '@payloadcms/richtext-lexical' export default buildConfig({ collections: [ // your collections here ], // Pass the Lexical editor to the root config editor: lexicalEditor({}), }) ``` You can also override Lexical settings on a field-by-field basis as follows: ```ts import type { CollectionConfig } from 'payload' import { lexicalEditor } from '@payloadcms/richtext-lexical' export const Pages: CollectionConfig = { slug: 'pages', fields: [ { name: 'content', type: 'richText', // Pass the Lexical editor here and override base settings as necessary editor: lexicalEditor({}), }, ], } ``` ## Extending the lexical editor with Features Lexical has been designed with extensibility in mind. Whether you're aiming to introduce new functionalities or tweak the existing ones, Lexical makes it seamless for you to bring those changes to life. ### Features: The Building Blocks At the heart of Lexical's customization potential are "features". While Lexical ships with a set of default features we believe are essential for most use cases, the true power lies in your ability to redefine, expand, or prune these as needed. If you remove all the default features, you're left with a blank editor. You can then add in only the features you need, or you can build your own custom features from scratch. ### Integrating New Features To weave in your custom features, utilize the `features` prop when initializing the Lexical Editor. Here's a basic example of how this is done: ```ts import { BlocksFeature, LinkFeature, UploadFeature, lexicalEditor, } from '@payloadcms/richtext-lexical' import { Banner } from '../blocks/Banner' import { CallToAction } from '../blocks/CallToAction' { editor: lexicalEditor({ features: ({ defaultFeatures, rootFeatures }) => [ ...defaultFeatures, LinkFeature({ // Example showing how to customize the built-in fields // of the Link feature fields: ({ defaultFields }) => [ ...defaultFields, { name: 'rel', label: 'Rel Attribute', type: 'select', hasMany: true, options: ['noopener', 'noreferrer', 'nofollow'], admin: { description: 'The rel attribute defines the relationship between a linked resource and the current document. This is a custom link field.', }, }, ], }), UploadFeature({ collections: { uploads: { // Example showing how to customize the built-in fields // of the Upload feature fields: [ { name: 'caption', type: 'richText', editor: lexicalEditor(), }, ], }, }, }), // This is incredibly powerful. You can re-use your Payload blocks // directly in the Lexical editor as follows: BlocksFeature({ blocks: [Banner, CallToAction], }), ], }) } ``` `features` can be both an array of features, or a function returning an array of features. The function provides the following props: | Prop | Description | |-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | **`defaultFeatures`** | This opinionated array contains all "recommended" default features. You can see which features are included in the default features in the table below. | | **`rootFeatures`** | This array contains all features that are enabled in the root richText editor (the one defined in the payload.config.ts). If this field is the root richText editor, or if the root richText editor is not a lexical editor, this array will be empty. | ## Features overview Here's an overview of all the included features: | Feature Name | Included by default | Description | |---------------------------------|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | **`BoldTextFeature`** | Yes | Handles the bold text format | | **`ItalicTextFeature`** | Yes | Handles the italic text format | | **`UnderlineTextFeature`** | Yes | Handles the underline text format | | **`StrikethroughTextFeature`** | Yes | Handles the strikethrough text format | | **`SubscriptTextFeature`** | Yes | Handles the subscript text format | | **`SuperscriptTextFeature`** | Yes | Handles the superscript text format | | **`InlineCodeTextFeature`** | Yes | Handles the inline-code text format | | **`ParagraphFeature`** | Yes | Handles paragraphs. Since they are already a key feature of lexical itself, this Feature mainly handles the Slash and Add-Block menu entries for paragraphs | | **`HeadingFeature`** | Yes | Adds Heading Nodes (by default, H1 - H6, but that can be customized) | | **`AlignFeature`** | Yes | Allows you to align text left, centered and right | | **`IndentFeature`** | Yes | Allows you to indent text with the tab key | | **`UnorderedListFeature`** | Yes | Adds unordered lists (ul) | | **`OrderedListFeature`** | Yes | Adds ordered lists (ol) | | **`CheckListFeature`** | Yes | Adds checklists | | **`LinkFeature`** | Yes | Allows you to create internal and external links | | **`RelationshipFeature`** | Yes | Allows you to create block-level (not inline) relationships to other documents | | **`BlockQuoteFeature`** | Yes | Allows you to create block-level quotes | | **`UploadFeature`** | Yes | Allows you to create block-level upload nodes - this supports all kinds of uploads, not just images | | **`HorizontalRuleFeature`** | Yes | Horizontal rules / separators. Basically displays an `