Lexical — Extensible Rich Text Editor Framework by Meta
Lexical is an extensible text editor framework from Meta providing excellent reliability, accessibility, and performance. Powers Facebook posts, comments, and messaging — designed for modern collaborative editing.
What it is
Lexical is an extensible text editor framework from Meta. It provides the core editor engine and a plugin system for building rich text editors with excellent reliability, accessibility, and performance. Lexical powers Facebook posts, comments, and messaging. It is designed around an immutable state model that makes collaborative editing and undo/redo straightforward.
Lexical is designed for frontend developers building rich text editing experiences in React or vanilla JavaScript applications.
How it saves time or tokens
Building a rich text editor from scratch is one of the hardest frontend challenges: content editable behavior is inconsistent across browsers, accessibility requirements are complex, and collaborative editing needs a solid state model. Lexical provides all of this as a framework. The plugin system lets you add features (mentions, hashtags, tables, embeds) incrementally without modifying the core editor. A production-quality editor that would take months to build from scratch can be assembled from Lexical plugins in days.
How to use
- Install Lexical with React bindings:
npm install lexical @lexical/react
- Create a basic rich text editor:
import { LexicalComposer } from '@lexical/react/LexicalComposer';
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
const initialConfig = {
namespace: 'MyEditor',
onError: (error: Error) => console.error(error),
};
export function Editor() {
return (
<LexicalComposer initialConfig={initialConfig}>
<RichTextPlugin
contentEditable={<ContentEditable />}
ErrorBoundary={LexicalErrorBoundary}
/>
<HistoryPlugin />
</LexicalComposer>
);
}
- Add plugins for additional features (toolbar, mentions, tables, etc.).
Example
Adding a toolbar with bold, italic, and link formatting:
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import { FORMAT_TEXT_COMMAND } from 'lexical';
function ToolbarPlugin() {
const [editor] = useLexicalComposerContext();
return (
<div className='toolbar'>
<button onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold')}>
Bold
</button>
<button onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic')}>
Italic
</button>
</div>
);
}
Related on TokRepo
- Coding tools — Browse frontend development tools
- Documentation tools — Explore text editing and documentation tools
Common pitfalls
- Trying to access the DOM directly instead of using Lexical's state model. Lexical manages the DOM through its editor state. Direct DOM manipulation will break the editor's state synchronization.
- Not wrapping plugins inside LexicalComposer. All Lexical plugins must be children of the LexicalComposer component. Plugins outside the composer cannot access the editor instance.
- Ignoring accessibility from the start. Lexical provides excellent accessibility primitives, but you must use them correctly in custom plugins. Test with screen readers during development, not as an afterthought.
Frequently Asked Questions
Both are extensible editor frameworks. Lexical uses an immutable state model with a command-based architecture, making it more predictable for complex features. Slate uses a mutable model with transforms. Lexical is backed by Meta and powers Facebook's editors; Slate has a longer community history.
Yes. Lexical's core (the lexical package) is framework-agnostic. The @lexical/react package provides React-specific bindings. You can use Lexical with vanilla JavaScript or other frameworks.
Lexical's immutable state model is designed to support collaborative editing. You integrate a CRDT or OT library (like Yjs) with Lexical's state updates to enable real-time collaboration.
Yes. Lexical powers Facebook posts, comments, and Messenger. It handles billions of editor interactions daily. The framework is battle-tested at Meta's scale.
Yes. Lexical's plugin system supports blocks, embeds, tables, mentions, and custom node types. Building a Notion-like experience requires significant custom development, but Lexical provides the right foundation.
Citations (3)
- Lexical GitHub— Lexical is an extensible editor framework by Meta
- Lexical Documentation— Plugin-based architecture for rich text editing
- Lexical React— React bindings for Lexical