Sign up (with export icon)

Integrating CKEditor 5 with jQuery using npm

Contribute to this guide Show the table of contents

This guide will walk you through the process of integrating CKEditor 5 with jQuery using npm packages. jQuery is a fast, small, and feature-rich JavaScript library that simplifies HTML document traversal and manipulation, event handling, and animation. By combining it with CKEditor 5 using npm packages, you can leverage jQuery’s powerful DOM manipulation capabilities while enjoying the rich editing experience that CKEditor 5 provides.

Create your own CKEditor 5

Check out our interactive Builder to quickly get a taste of CKEditor 5. It offers an easy-to-use user interface to help you configure, preview, and download the editor suited to your needs.

  • editor type,
  • the features you need,
  • the preferred framework (React, Angular, Vue or Vanilla JS),
  • the preferred distribution method.

You get ready-to-use code tailored to your needs!

Check out our interactive Builder

Installing CKEditor 5 using npm

Copy link
Note

To set up the editor from npm, you need a bundler to build the JavaScript files correctly. CKEditor 5 is compatible with all modern JavaScript bundlers. For a quick project setup, we recommend using Vite.

To begin integrating CKEditor 5 with jQuery, you first need to install the required packages using npm. This approach provides access to all the necessary files including the editor engine, plugins, and style sheets that you can import directly into your application.

Install CKEditor 5 using npm by running the following command in your project directory:

npm install ckeditor5
Copy code

You also need to install jQuery if you have not done so already:

npm install jquery
Copy code

Once the packages are installed, you can import the necessary modules and style sheets directly into your JavaScript code. Create a JavaScript file for your application logic, then import CKEditor 5 and jQuery.

Note

Starting from version 44.0.0, the licenseKey property is required to use the editor. If you use a self-hosted editor from npm:

You can set up a free trial to test the editor and evaluate the self-hosting.

Here is the complete integration code combining jQuery and CKEditor 5:

import $ from 'jquery';

import { ClassicEditor, Essentials, Bold, Italic, Font, Paragraph } from 'ckeditor5';

import 'ckeditor5/ckeditor5.css';

$( document ).ready( () => {
    ClassicEditor
        .create( $( '#editor' )[ 0 ], {
            licenseKey: '<YOUR_LICENSE_KEY>', // Or 'GPL'.
            plugins: [ Essentials, Bold, Italic, Font, Paragraph ],
            toolbar: [
                'undo', 'redo', '|', 'bold', 'italic', '|',
                'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor'
            ]
        } )
        .then( editor => {
            // Editor initialized successfully.
            console.log( 'CKEditor&nbsp;5 initialized with jQuery!' );
        } )
        .catch( error => {
            console.error( 'Error initializing CKEditor&nbsp;5:', error );
        } );
} );
Copy code

Pass the imported plugins inside the configuration to the create() method and add toolbar items where applicable.

The first argument in the create() function is a DOM element for the editor placement, so you need to add it to your HTML page.

<div id="editor">
    <p>Hello from CKEditor&nbsp;5 with jQuery!</p>
</div>
Copy code

That is all the code you need to see a bare-bone editor running in your web browser.

Installing CKEditor 5 Premium Features using npm

Copy link

To extend your CKEditor 5 and jQuery integration with premium features, you need to install the premium features package separately.

Install the CKEditor 5 Premium Features package using npm by running the following command in your project directory:

npm install ckeditor5-premium-features
Copy code

Now, you can import all the modules from both the ckeditor5 and ckeditor5-premium-features packages. Additionally, you have to import CSS styles separately.

import $ from 'jquery';

import { ClassicEditor, Essentials, Bold, Italic, Font, Paragraph } from 'ckeditor5';
import { FormatPainter } from 'ckeditor5-premium-features';

import 'ckeditor5/ckeditor5.css';
import 'ckeditor5-premium-features/ckeditor5-premium-features.css';

$( document ).ready( () => {
    ClassicEditor
        .create( $( '#editor' )[ 0 ], {
            licenseKey: '<YOUR_LICENSE_KEY>',
            plugins: [ Essentials, Bold, Italic, Font, Paragraph, FormatPainter ],
            toolbar: [
                'undo', 'redo', '|', 'bold', 'italic', '|',
                'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', '|',
                'formatPainter'
            ]
        } )
        .then( editor => {
            // Editor initialized successfully with premium features.
            console.log( 'CKEditor&nbsp;5 with premium features initialized using jQuery!' );
        } )
        .catch( error => {
            console.error( 'Error initializing CKEditor&nbsp;5 with premium features:', error );
        } );
} );
Copy code

Obtaining a premium features license key

Copy link

To activate CKEditor 5 premium features, you will need a commercial license. The easiest way to get one is to sign up for the CKEditor Premium Features 14-day free trial.

You can also contact us to receive an offer tailored to your needs. To obtain an activation key, please follow the License key and activation guide.

Next steps

Copy link