To add a rich text editor to a website today, use CKEditor 5: install it with npm or load it from the official CDN, turn a <textarea> or <div> into an editor with ClassicEditor.create(), and read the content with editor.getData(). CKEditor 4, which uses CKEDITOR.replace(), reached end of life in June 2023, so new projects should not use it.
This guide shows both a CDN setup and an npm setup, how to submit the edited content with a form, how to keep it safe, and what the alternatives are.
The old tutorial pattern downloads the CKEditor 4 package, includes ckeditor.js and calls CKEDITOR.replace('content'). That version no longer receives regular updates, and unpatched editors are a security risk.
| CKEditor 4 | CKEditor 5 | |
|---|---|---|
| Status | End of life since June 2023 (paid extended support only) | Actively developed |
| Setup | One script plus CKEDITOR.replace() | ES modules, CDN or npm build |
| API | CKEDITOR global object | ClassicEditor.create() returns a promise |
| Architecture | Older, HTML-based | Modern, with its own data model |
If you maintain a site that still uses CKEditor 4, plan a migration to CKEditor 5 or another editor.
The quickest route needs no build tool. Look up the current version and the exact snippet in the official CKEditor 5 installation documentation, then use it with an import map like this one. Replace X.Y.Z with the version number you choose.
This code loads the editor as an ES module, picks only the plugins you need, and replaces the textarea with the editor. CKEditor 5 updates the original textarea when the form is submitted, so a normal form post sends the HTML.
The licenseKey: 'GPL' setting is for open source use under the GPL. Commercial projects need a license key from CKSource. Check the licensing page for your case.
For an application with a bundler such as Vite, install the package.
Then import the editor and its CSS in your script.
Use a <div id="editor"> as the mount element when you are not using a form. Call editor.getData() to read the HTML, editor.setData(html) to replace it, and editor.destroy() when the component is removed.
An editor produces HTML, so never trust it on the server.
The editor's own filtering protects the editing session only. It is not a replacement for server-side sanitising.
| Editor | Notes |
|---|---|
| TinyMCE | Mature WYSIWYG editor with a cloud and self-hosted option |
| Tiptap | Headless editor built on ProseMirror, good for custom interfaces |
| Lexical | Editor framework from Meta, used in React and other apps |
| Quill | Lightweight editor with a simple API |
If you need Markdown rather than HTML, a Markdown editor with preview is often simpler to secure and store.
CKEditor 5 can be used under the GPL for open source projects. Commercial and closed-source use needs a commercial licence. Read the current licence terms before you ship.
It still runs, but it has been end of life since June 2023 and gets no free security updates. Migrate to CKEditor 5 or another maintained editor.
Call editor.getData() on the instance returned by ClassicEditor.create(). In a form, the textarea value is updated for you on submit.
Yes. CKEditor provides official integrations for these frameworks, which wrap the same editor in a component.
Use CKEditor 5 for any new project, load it from the CDN for a quick start or install it with npm for an application, and read the content with editor.getData(). Always sanitise the submitted HTML on the server, and move off CKEditor 4 if you still run it.