lexical
Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
Top Related Projects
A browser based code editor
Quill is a modern WYSIWYG editor built for compatibility and extensibility
A completely customizable framework for building rich text editors. (Currently in beta.)
The world's #1 JavaScript library for rich text editing. Available for React, Vue and Angular
Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
In-browser code editor (version 5, legacy)
Quick Overview
Lexical is an extensible text editor framework developed by Facebook. It provides a robust foundation for building rich text editing experiences in web applications, with a focus on performance, accessibility, and extensibility.
Pros
- High performance and efficiency, even with large documents
- Extensible architecture allowing for custom plugins and features
- Strong focus on accessibility and internationalization
- Lightweight core with modular design
Cons
- Relatively new project, still evolving and may have some stability issues
- Learning curve for developers unfamiliar with the architecture
- Limited ecosystem compared to more established editors
- Documentation could be more comprehensive for advanced use cases
Code Examples
- Basic Editor Setup:
import {$getRoot, $getSelection} from 'lexical';
import {LexicalComposer} from '@lexical/react/LexicalComposer';
import {PlainTextPlugin} from '@lexical/react/LexicalPlainTextPlugin';
import {ContentEditable} from '@lexical/react/LexicalContentEditable';
import {HistoryPlugin} from '@lexical/react/LexicalHistoryPlugin';
function Editor() {
const initialConfig = {
namespace: 'MyEditor',
onError: (error) => console.error(error),
};
return (
<LexicalComposer initialConfig={initialConfig}>
<PlainTextPlugin
contentEditable={<ContentEditable />}
placeholder={<div>Enter some text...</div>}
/>
<HistoryPlugin />
</LexicalComposer>
);
}
- Custom Plugin Creation:
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
function MyCustomPlugin() {
const [editor] = useLexicalComposerContext();
useEffect(() => {
return editor.registerUpdateListener(({editorState}) => {
editorState.read(() => {
// Custom logic here
});
});
}, [editor]);
return null;
}
- Rich Text Formatting:
import {$getSelection, $isRangeSelection} from 'lexical';
import {FORMAT_TEXT_COMMAND} from 'lexical';
function formatText(formatType) {
editor.update(() => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
selection.formatText(formatType);
}
});
}
// Usage
<button onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold')}>
Bold
</button>
Getting Started
-
Install Lexical and its React package:
npm install lexical @lexical/react -
Create a basic editor component:
import {LexicalComposer} from '@lexical/react/LexicalComposer'; import {PlainTextPlugin} from '@lexical/react/LexicalPlainTextPlugin'; import {ContentEditable} from '@lexical/react/LexicalContentEditable'; function Editor() { const initialConfig = { namespace: 'MyEditor', onError: (error) => console.error(error), }; return ( <LexicalComposer initialConfig={initialConfig}> <PlainTextPlugin contentEditable={<ContentEditable />} placeholder={<div>Enter some text...</div>} /> </LexicalComposer> ); } -
Use the editor component in your React application.
Competitor Comparisons
A browser based code editor
Pros of Monaco Editor
- More mature and widely adopted, with extensive documentation and community support
- Offers advanced features like IntelliSense, code folding, and multi-language support
- Highly customizable with a rich set of APIs for extending functionality
Cons of Monaco Editor
- Larger bundle size, which may impact load times for web applications
- Steeper learning curve due to its extensive feature set and configuration options
- Less suitable for simple text editing scenarios where a lightweight solution is preferred
Code Comparison
Monaco Editor:
import * as monaco from 'monaco-editor';
monaco.editor.create(document.getElementById('container'), {
value: 'function hello() {\n\tconsole.log("Hello world!");\n}',
language: 'javascript'
});
Lexical:
import {$getRoot, $createParagraphNode} from 'lexical';
import {LexicalComposer} from '@lexical/react/LexicalComposer';
const initialConfig = {
namespace: 'MyEditor',
onError: (error) => console.error(error),
};
Summary
Monaco Editor is a powerful, feature-rich code editor with extensive language support, making it ideal for complex development environments. Lexical, on the other hand, is a more lightweight and flexible text editing framework, better suited for content-focused applications and simpler editing scenarios. The choice between the two depends on the specific requirements of your project and the level of editing functionality needed.
Quill is a modern WYSIWYG editor built for compatibility and extensibility
Pros of Quill
- More mature and established project with a larger community and ecosystem
- Easier to get started with for simple use cases
- Better documentation and examples available
Cons of Quill
- Less flexible and extensible compared to Lexical's modular architecture
- Performance may be slower for complex documents or large-scale applications
- Limited support for collaborative editing features out of the box
Code Comparison
Quill:
var quill = new Quill('#editor', {
theme: 'snow'
});
quill.on('text-change', function(delta, oldDelta, source) {
console.log('Text changed!');
});
Lexical:
const editor = createEditor({
theme: MyCustomTheme,
onError: (error) => console.error(error),
});
editor.registerUpdateListener(({editorState}) => {
editorState.read(() => {
console.log('Editor updated!');
});
});
Both Quill and Lexical are powerful rich text editors, but they have different approaches. Quill is more straightforward to implement for basic use cases, while Lexical offers greater flexibility and control over the editing experience. Lexical's modular architecture allows for more customization and better performance in complex scenarios, but it may require more setup and configuration. Quill's mature ecosystem and documentation make it easier for beginners to get started, but it may be less suitable for advanced use cases or large-scale applications.
A completely customizable framework for building rich text editors. (Currently in beta.)
Pros of Slate
- More mature and established project with a larger community
- Highly customizable and extensible architecture
- Better documentation and examples
Cons of Slate
- Steeper learning curve due to its flexibility
- Larger bundle size compared to Lexical
- Less frequent updates and maintenance
Code Comparison
Slate:
import { Editor } from 'slate-react'
const MyEditor = () => (
<Editor
value={initialValue}
onChange={value => setValue(value)}
/>
)
Lexical:
import { LexicalComposer } from '@lexical/react/LexicalComposer'
const MyEditor = () => (
<LexicalComposer initialConfig={editorConfig}>
<PlainTextPlugin />
</LexicalComposer>
)
Both Slate and Lexical are powerful rich text editing frameworks for React applications. Slate offers more flexibility and customization options, making it suitable for complex editing scenarios. However, this comes at the cost of a steeper learning curve and larger bundle size.
Lexical, being newer and developed by Facebook, focuses on simplicity and performance. It has a smaller footprint and is easier to get started with, but may lack some advanced features found in Slate.
Choose Slate for highly customized editing experiences, and Lexical for simpler, performance-focused implementations.
The world's #1 JavaScript library for rich text editing. Available for React, Vue and Angular
Pros of TinyMCE
- Mature and widely adopted WYSIWYG editor with extensive documentation
- Rich plugin ecosystem and customization options
- Supports a wide range of browsers and platforms
Cons of TinyMCE
- Larger file size and potentially slower performance
- Steeper learning curve for advanced customizations
- Less modern architecture compared to newer alternatives
Code Comparison
TinyMCE initialization:
tinymce.init({
selector: '#myTextarea',
plugins: 'link image table',
toolbar: 'undo redo | formatselect | bold italic | alignleft aligncenter alignright'
});
Lexical initialization:
const editor = new LexicalComposer({
nodes: [HeadingNode, ListNode, ListItemNode],
theme: {
// Theme configuration
},
});
TinyMCE focuses on configuration-based setup, while Lexical uses a more modular, component-based approach. TinyMCE offers a wider range of built-in features out of the box, whereas Lexical provides a more flexible foundation for custom editor experiences.
Lexical, being newer and developed by Facebook, employs modern React patterns and offers better performance for complex editing scenarios. However, TinyMCE's maturity and extensive plugin ecosystem make it a solid choice for projects requiring traditional rich text editing capabilities.
Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
Pros of CKEditor 5
- More mature and feature-rich, with a wider range of plugins and customization options
- Better documentation and community support
- Built-in accessibility features and compliance with WCAG 2.0 standards
Cons of CKEditor 5
- Larger bundle size and potentially slower performance
- Steeper learning curve for developers due to its complex architecture
- Less flexibility in terms of core editor customization
Code Comparison
CKEditor 5:
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
ClassicEditor
.create(document.querySelector('#editor'))
.then(editor => {
console.log('Editor was initialized', editor);
})
.catch(error => {
console.error(error);
});
Lexical:
import {$getRoot, $createParagraphNode, $createTextNode} from 'lexical';
editor.update(() => {
const root = $getRoot();
const paragraph = $createParagraphNode();
const text = $createTextNode('Hello world');
paragraph.append(text);
root.append(paragraph);
});
Both CKEditor 5 and Lexical are powerful rich text editors, but they cater to different needs. CKEditor 5 offers a more comprehensive out-of-the-box solution with extensive features and plugins, making it suitable for complex content creation scenarios. Lexical, on the other hand, provides a lightweight and flexible foundation for building custom editors, allowing developers more control over the core functionality and performance optimization.
In-browser code editor (version 5, legacy)
Pros of CodeMirror 5
- Mature and widely adopted, with extensive documentation and community support
- Highly customizable with a rich set of plugins and themes
- Excellent performance for handling large documents
Cons of CodeMirror 5
- Older architecture, not built with modern web technologies in mind
- Less focus on collaborative editing features
- Steeper learning curve for complex customizations
Code Comparison
Lexical:
import {$getRoot, $createParagraphNode, $createTextNode} from 'lexical';
editor.update(() => {
const root = $getRoot();
const paragraph = $createParagraphNode();
paragraph.append($createTextNode('Hello world'));
root.append(paragraph);
});
CodeMirror 5:
var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
lineNumbers: true,
mode: "javascript"
});
editor.setValue("Hello world");
Both Lexical and CodeMirror 5 are powerful text editing libraries, but they cater to different use cases. Lexical is designed for modern web applications with a focus on extensibility and collaborative editing, while CodeMirror 5 is a mature and feature-rich editor with excellent performance for traditional coding scenarios. The choice between them depends on specific project requirements and the desired balance between modern features and established reliability.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
An extensible text editor framework that provides excellent reliability, accessibility and performance.
Documentation | Getting Started | Playground | Gallery
Features
- Framework Agnostic Core - Works with any UI framework, with official React bindings
- Reliable & Accessible - Built-in accessibility support and WCAG compliance
- Extensible - Plugin-based architecture with powerful extension points
- Immutable State Model - Time-travel ready with built-in undo/redo
- Collaborative Editing - Real-time collaboration via Yjs integration
- Serialization - Import/export from JSON, Markdown, and HTML
- Rich Content - Support for tables, lists, code blocks, images, and custom nodes
- Cross-browser - Firefox 52+, Chrome 49+, Safari 11+, Edge 79+
- Type Safe - Written in TypeScript with comprehensive type definitions
Quick Start
npm install lexical @lexical/react
import { $getRoot, $getSelection } from 'lexical';
import { LexicalComposer } from '@lexical/react/LexicalComposer';
import { PlainTextPlugin } from '@lexical/react/LexicalPlainTextPlugin';
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
const initialConfig = {
namespace: 'MyEditor',
onError: (error) => console.error(error),
};
function Editor() {
return (
<LexicalComposer initialConfig={initialConfig}>
<PlainTextPlugin
contentEditable={<ContentEditable />}
ErrorBoundary={LexicalErrorBoundary}
/>
<HistoryPlugin />
</LexicalComposer>
);
}
Try it yourself:
Development
# Install dependencies
pnpm install
# Start playground dev server
pnpm run start
# Run tests
pnpm run test-unit
pnpm run test-e2e-chromium
# Lint and type check
pnpm run ci-check
See CONTRIBUTING.md for detailed development guidelines.
Documentation
- User Guide: lexical.dev/docs/intro
- API Reference: lexical.dev/docs/api
- Developer Guide: AGENTS.md - Architecture and development workflows
- Examples: examples/ - Sample implementations
Community & Support
- Discord: Join our Discord server for questions and discussions
- Twitter: Follow @lexicaljs for updates
- Issues: Report bugs and request features on GitHub Issues
Browser Support
| Browser | Version |
|---|---|
| Chrome | 49+ |
| Firefox | 52+ |
| Safari | 11+ |
| Edge | 79+ |
Contributors
We welcome contributions! Please read our Contributing Guide to learn about our development process and how to propose bugfixes and improvements.
License
MIT License © Meta Platforms, Inc.
Top Related Projects
A browser based code editor
Quill is a modern WYSIWYG editor built for compatibility and extensibility
A completely customizable framework for building rich text editors. (Currently in beta.)
The world's #1 JavaScript library for rich text editing. Available for React, Vue and Angular
Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
In-browser code editor (version 5, legacy)
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot