NEWCKEditor AI on your premises: Hook your LLM and register MCP tools. Webinar coming soon!
Sign up (with export icon)

Installing Vanilla JS CKEditor 5 from CDN

Contribute to this guideShow the table of contents

CKEditor 5 is a powerful, rich text editor you can embed in your web application. This guide will show you the fastest way to start using it.

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 from CDN

Copy link
Note

To use our Cloud CDN services, create a free account. Learn more about license key activation.

CDN is an alternative method of running CKEditor 5. You can start using it in just a few steps and with a few tags.

Start by attaching a link to style sheets. They contain all styles for the editor’s UI and content. You can also include your styles if you like. Refer to the content styles guide for more information.

<link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5/47.5.0/ckeditor5.css" />
Copy code
Tip

If you would not rather use the global variables presented below, you can continue from here and use an alternative, more advanced setup with import maps.

Then, you need to attach the script with the JavaScript code.

<script src="https://cdn.ckeditor.com/ckeditor5/47.5.0/ckeditor5.umd.js"></script>
Copy code

Import the selected editor type and plugins. The included script exposes the global variable named CKEDITOR. You can use object destructuring, shown below, to access the editor class and plugins.

const {
    ClassicEditor,
    Essentials,
    Bold,
    Italic,
    Font,
    Paragraph
} = CKEDITOR;

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        licenseKey: '<YOUR_LICENSE_KEY>',
        plugins: [ Essentials, Bold, Italic, Font, Paragraph ],
        toolbar: [
            'undo', 'redo', '|', 'bold', 'italic', '|',
            'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor'
        ]
    } )
    .then( /* ... */ )
    .catch( /* ... */ );
Copy code

Lastly, add a tag for the editor to attach to. Ensure the query selector matches the HTML element ID (or class).

<div id="editor">
    <p>Hello from CKEditor 5!</p>
</div>
Copy code

A simple HTML page with the CKEditor may look like the one below.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>CKEditor 5 - Quick start CDN</title>
        <link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5/47.5.0/ckeditor5.css" />
    </head>
    <body>
        <div id="editor">
            <p>Hello from CKEditor 5!</p>
        </div>

        <script src="https://cdn.ckeditor.com/ckeditor5/47.5.0/ckeditor5.umd.js"></script>

        <script>
            const {
                ClassicEditor,
                Essentials,
                Bold,
                Italic,
                Font,
                Paragraph
            } = CKEDITOR;

            ClassicEditor
                .create( document.querySelector( '#editor' ), {
                    licenseKey: '<YOUR_LICENSE_KEY>',
                    plugins: [ Essentials, Bold, Italic, Font, Paragraph ],
                    toolbar: [
                        'undo', 'redo', '|', 'bold', 'italic', '|',
                        'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor'
                    ]
                } )
                .then( /* ... */ )
                .catch( /* ... */ );
        </script>
    </body>
</html>
Copy code

Installing premium features from CDN

Copy link

Just like with open-source features, start by attaching a link to style sheets. They contain all styles for the editor’s UI and content. The styles are in two separate style sheets – for open-source and premium plugins. You can also include your styles if you like. Refer to the content styles guide for more information.

<link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5/47.5.0/ckeditor5.css" />

<link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5-premium-features/47.5.0/ckeditor5-premium-features.css" />
Copy code
Tip

If you do not want to use the global variables presented below, you can continue from here and use an alternative, more advanced setup with import maps.

Then, you need to attach the script tags with the JavaScript code. Similar to style sheets, there are separate scripts for open-source and premium plugins.

<script src="https://cdn.ckeditor.com/ckeditor5/47.5.0/ckeditor5.umd.js"></script>

<script src="https://cdn.ckeditor.com/ckeditor5-premium-features/47.5.0/ckeditor5-premium-features.umd.js"></script>
Copy code

Both included scripts expose global variables named CKEDITOR and CKEDITOR_PREMIUM_FEATURES. You can use object destructuring, shown below, to access the editor class and plugins. Open-source and premium features are in the respective global variables.

<script>
    const {
        ClassicEditor,
        Essentials,
        Bold,
        Italic,
        Font,
        Paragraph
    } = CKEDITOR;
    const { FormatPainter } = CKEDITOR_PREMIUM_FEATURES;

    ClassicEditor
        .create( document.querySelector( '#editor' ), {
            licenseKey: '<YOUR_LICENSE_KEY>',
            plugins: [ Essentials, Bold, Italic, Font, Paragraph, FormatPainter ],
            toolbar: [
                'undo', 'redo', '|', 'bold', 'italic', '|',
                'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', '|',
                'formatPainter'
            ]
        } )
        .then( /* ... */ )
        .catch( /* ... */ );
</script>
Copy code

Lastly, add a tag for the editor to attach to. Ensure the query selector matches the HTML element ID (or class).

<div id="editor">
    <p>Hello from CKEditor 5!</p>
</div>
Copy code

A simple HTML page with the CKEditor may look like the one below.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>CKEditor 5 - Quick start CDN</title>
        <link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5/47.5.0/ckeditor5.css" />
        <link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5-premium-features/47.5.0/ckeditor5-premium-features.css" />
    </head>
    <body>
        <div id="editor">
            <p>Hello from CKEditor 5!</p>
        </div>

        <script src="https://cdn.ckeditor.com/ckeditor5/47.5.0/ckeditor5.umd.js"></script>
        <script src="https://cdn.ckeditor.com/ckeditor5-premium-features/47.5.0/ckeditor5-premium-features.umd.js"></script>

        <script>
            const {
                ClassicEditor,
                Essentials,
                Bold,
                Italic,
                Font,
                Paragraph
            } = CKEDITOR;
            const { FormatPainter } = CKEDITOR_PREMIUM_FEATURES;

            ClassicEditor
                .create( document.querySelector( '#editor' ), {
                    licenseKey: '<YOUR_LICENSE_KEY>',
                    plugins: [ Essentials, Bold, Italic, Font, Paragraph, FormatPainter ],
                    toolbar: [
                        'undo', 'redo', '|', 'bold', 'italic', '|',
                        'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', '|',
                        'formatPainter'
                    ]
                } )
                .then( /* ... */ )
                .catch( /* ... */ );
        </script>
    </body>
</html>
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.

Advanced setup with import maps

Copy link

To simplify imports, you can use the feature available in browsers – the import map. It allows us to map an easy-to-remember specifier (like ckeditor5 or ckeditor5-premium-features) to the full URL of the file from the CDN. We use this browser feature to share an editor engine code between plugins. Open source and premium plugins have their respective specifiers. Add mapping for premium features only if you use them.

<script type="importmap">
    {
        "imports": {
            "ckeditor5": "https://cdn.ckeditor.com/ckeditor5/47.5.0/ckeditor5.js",
            "ckeditor5/": "https://cdn.ckeditor.com/ckeditor5/47.5.0/",
            "ckeditor5-premium-features": "https://cdn.ckeditor.com/ckeditor5-premium-features/47.5.0/ckeditor5-premium-features.js",
            "ckeditor5-premium-features/": "https://cdn.ckeditor.com/ckeditor5-premium-features/47.5.0/"
        }
    }
</script>
Copy code

Once you have added the import map, you can access the editor and its plugins using the defined specifiers. Now, you can use standard ESM imports from the ckeditor5 and ckeditor5-premium-features packages, like import { ClassicEditor } from 'ckeditor5';. Please note that to use premium features, you need to activate them with a proper license key, as mentioned in the Obtaining a license key section.

In the following script tag, import the desired plugins and add them to the plugins array, and add toolbar items where applicable. Note that both script tags (this and the previous) have the appropriate type values.

<script type="module">
    import {
        ClassicEditor,
        Essentials,
        Bold,
        Italic,
        Font,
        Paragraph
    } from 'ckeditor5';
    import { FormatPainter } from 'ckeditor5-premium-features';

    ClassicEditor
        .create( document.querySelector( '#editor' ), {
            licenseKey: '<YOUR_LICENSE_KEY>',
            plugins: [ Essentials, Bold, Italic, Font, Paragraph, FormatPainter ],
            toolbar: [
                'undo', 'redo', '|', 'bold', 'italic', '|',
                'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', '|', 'formatPainter'
            ]
        } )
        .then( /* ... */ )
        .catch( /* ... */ );
</script>
Copy code

Your final page should look similar to the one below.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>CKEditor 5 - Quick start CDN</title>
        <link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5/47.5.0/ckeditor5.css" />
        <link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5-premium-features/47.5.0/ckeditor5-premium-features.css" />
    </head>
    <body>
        <div id="editor">
            <p>Hello from CKEditor 5!</p>
        </div>

        <script type="importmap">
            {
                "imports": {
                    "ckeditor5": "https://cdn.ckeditor.com/ckeditor5/47.5.0/ckeditor5.js",
                    "ckeditor5/": "https://cdn.ckeditor.com/ckeditor5/47.5.0/",
                    "ckeditor5-premium-features": "https://cdn.ckeditor.com/ckeditor5-premium-features/47.5.0/ckeditor5-premium-features.js",
                    "ckeditor5-premium-features/": "https://cdn.ckeditor.com/ckeditor5-premium-features/47.5.0/"
                }
            }
        </script>

        <script type="module">
            import {
                ClassicEditor,
                Essentials,
                Bold,
                Italic,
                Font,
                Paragraph
            } from 'ckeditor5';
            import { FormatPainter } from 'ckeditor5-premium-features';

            ClassicEditor
                .create( document.querySelector( '#editor' ), {
                    licenseKey: '<YOUR_LICENSE_KEY>',
                    plugins: [ Essentials, Bold, Italic, Font, Paragraph, FormatPainter ],
                    toolbar: [
                        'undo', 'redo', '|', 'bold', 'italic', '|',
                        'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', '|', 'formatPainter'
                    ]
                } )
                .then( /* ... */ )
                .catch( /* ... */ );
        </script>
    </body>
</html>
Copy code

Additional setup for Vite

Copy link

If you use UMD imports, you do not need to use any bundler. However, if your tooling enforces a Vite bundler or for some other reason you need one, follow the next steps.

Due to Vite limitations, using it with the cloud version of CKEditor 5 and ESM imports requires additional configuration. Vite does not fully support native import maps and external ESM modules (see Vite Issue #6582). Vite resolves imports at build time. Importing the editor using standard ESM syntax may force Vite to fall back to the UMD bundle, or it may cause errors.

To solve this issue, we can add a custom Vite plugin that externalizes CKEditor imports. This way, they can be resolved at runtime by the browser’s import map instead of being processed by Vite’s bundler. Below is the code of this plugin.

export function viteCKEditorExternalize() {
    return {
        name: 'ckeditor5-externalize',
        enforce: 'pre',
        config: ( config ) => {
            if ( config.optimizeDeps?.exclude && !Array.isArray( config.optimizeDeps.exclude ) ) {
                throw new Error( 'ckeditor5-externalize: config.optimizeDeps.exclude is not an array' );
            }

            if ( config.build?.rollupOptions?.external && !Array.isArray( config.build.rollupOptions.external ) ) {
                throw new Error( 'ckeditor5-externalize: config.build.rollupOptions.external is not an array' );
            }

            config.optimizeDeps ??= {};
            config.optimizeDeps.exclude = [
                ...( ( config.optimizeDeps.exclude ?? [] ) ),
                'ckeditor5',
                'ckeditor5-premium-features'
            ];

            config.build ??= {};
            config.build.rollupOptions ??= {};
            config.build.rollupOptions.external = [
                ...( ( config.build.rollupOptions.external ?? [] ) ),
                'ckeditor5',
                'ckeditor5-premium-features',
                /^ckeditor5\/.*/,
                /^ckeditor5-premium-features\/.*/
            ];
        },
        configResolved: ( resolvedConfig ) => {
            ( resolvedConfig.plugins ).push( {
                name: 'remove-id-prefix',
                transform: ( code ) => {
                    if ( typeof code === 'string' ) {
                        return code.replace( /\/@id\/ckeditor5/g, 'ckeditor5' );
                    }
                    return null;
                }
            } );
        },
        resolveId: ( id ) => {
            if (
                id === 'ckeditor5' ||
                id === 'ckeditor5-premium-features' ||
                id.startsWith( 'ckeditor5/' ) ||
                id.startsWith( 'ckeditor5-premium-features/' )
            ) {
                return {
                    id,
                    external: true
                };
            }
            return null;
        }
    };
}
Copy code

You need to add the plugin to the plugins array in the Vite config to use it in your project.

// vite.config.js
import { viteCKEditorExternalize } from './plugins/vite-ckeditor-externalize.js';

export default {
    plugins: [ viteCKEditorExternalize() ]
};
Copy code

The workaround should solve the issue and ensure a unified ESM development experience. Using this plugin, you can write clean ESM integration code regardless of the distribution channel.

Next steps

Copy link