Quick start

Creating an editor using a CKEditor 5 build is very simple and can be described in two steps:

  • Load the desired editor via the <script> tag.
  • Call the static create() method to create the editor.

There are other installation and integration methods available. For more information check Installation and Basic API guides.

Classic editor

In your HTML page add an element that CKEditor should replace:

  1. <textarea name="content" id="editor"></textarea>

Load the classic editor build (here CDN location is used):

  1. <script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/classic/ckeditor.js"></script>

Call the ClassicEditor.create() method.

  1. <script>
  2. ClassicEditor
  3. .create( document.querySelector( '#editor' ) )
  4. .catch( error => {
  5. console.error( error );
  6. } );
  7. </script>

Example

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CKEditor 5 – Classic editor</title>
  6. <script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/classic/ckeditor.js"></script>
  7. </head>
  8. <body>
  9. <h1>Classic editor</h1>
  10. <textarea name="content" id="editor">
  11. &lt;p&gt;This is some sample content.&lt;/p&gt;
  12. </textarea>
  13. <script>
  14. ClassicEditor
  15. .create( document.querySelector( '#editor' ) )
  16. .catch( error => {
  17. console.error( error );
  18. } );
  19. </script>
  20. </body>
  21. </html>

Inline editor

In your HTML page add an element that CKEditor should make editable:

  1. <div id="editor"></div>

Load the inline editor build (here CDN location is used):

  1. <script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/inline/ckeditor.js"></script>

Call the InlineEditor.create() method.

  1. <script>
  2. InlineEditor
  3. .create( document.querySelector( '#editor' ) )
  4. .catch( error => {
  5. console.error( error );
  6. } );
  7. </script>

Example

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CKEditor 5 - Inline editor</title>
  6. <script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/inline/ckeditor.js"></script>
  7. </head>
  8. <body>
  9. <h1>Inline editor</h1>
  10. <div id="editor">
  11. <p>This is some sample content.</p>
  12. </div>
  13. <script>
  14. InlineEditor
  15. .create( document.querySelector( '#editor' ) )
  16. .catch( error => {
  17. console.error( error );
  18. } );
  19. </script>
  20. </body>
  21. </html>

Balloon editor

In your HTML page add an element that CKEditor should make editable:

  1. <div id="editor"></div>

Load the balloon editor build (here CDN location is used):

  1. <script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/balloon/ckeditor.js"></script>

Call the BalloonEditor.create() method.

  1. <script>
  2. BalloonEditor
  3. .create( document.querySelector( '#editor' ) )
  4. .catch( error => {
  5. console.error( error );
  6. } );
  7. </script>

Example

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CKEditor 5 – Balloon editor</title>
  6. <script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/balloon/ckeditor.js"></script>
  7. </head>
  8. <body>
  9. <h1>Balloon editor</h1>
  10. <div id="editor">
  11. <p>This is some sample content.</p>
  12. </div>
  13. <script>
  14. BalloonEditor
  15. .create( document.querySelector( '#editor' ) )
  16. .catch( error => {
  17. console.error( error );
  18. } );
  19. </script>
  20. </body>
  21. </html>

Balloon block editor

In your HTML page add an element that CKEditor should make editable:

  1. <div id="editor"></div>

Load the balloon block editor build (here CDN location is used):

  1. <script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/balloon-block/ckeditor.js"></script>

Call the BalloonEditor.create() method.

  1. <script>
  2. BalloonEditor
  3. .create( document.querySelector( '#editor' ) )
  4. .catch( error => {
  5. console.error( error );
  6. } );
  7. </script>

Note: You can configure the block toolbar items using the config.blockToolbar option.

Example

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CKEditor 5 – Balloon block editor</title>
  6. <script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/balloon-block/ckeditor.js"></script>
  7. </head>
  8. <body>
  9. <h1>Balloon editor</h1>
  10. <div id="editor">
  11. <p>This is some sample content.</p>
  12. </div>
  13. <script>
  14. BalloonEditor
  15. .create( document.querySelector( '#editor' ) )
  16. .catch( error => {
  17. console.error( error );
  18. } );
  19. </script>
  20. </body>
  21. </html>

Document editor

Load the document editor build (here CDN location is used):

  1. <script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/decoupled-document/ckeditor.js"></script>

Call the DecoupledEditor.create() method. The decoupled editor requires you to inject the toolbar into the DOM and the best place to do that is somewhere in the promise chain (e.g. one of the then( () => { … } ) blocks).

The following snippet will run the document editor but to make the most of it check out the comprehensive tutorial which explains step—by—step how to configure and style the application for the best editing experience.

  1. <script>
  2. DecoupledEditor
  3. .create( document.querySelector( '#editor' ) )
  4. .then( editor => {
  5. const toolbarContainer = document.querySelector( '#toolbar-container' );
  6. toolbarContainer.appendChild( editor.ui.view.toolbar.element );
  7. } )
  8. .catch( error => {
  9. console.error( error );
  10. } );
  11. </script>

Example

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CKEditor 5 – Document editor</title>
  6. <script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/decoupled-document/ckeditor.js"></script>
  7. </head>
  8. <body>
  9. <h1>Document editor</h1>
  10. <!-- The toolbar will be rendered in this container. -->
  11. <div id="toolbar-container"></div>
  12. <!-- This container will become the editable. -->
  13. <div id="editor">
  14. <p>This is the initial editor content.</p>
  15. </div>
  16. <script>
  17. DecoupledEditor
  18. .create( document.querySelector( '#editor' ) )
  19. .then( editor => {
  20. const toolbarContainer = document.querySelector( '#toolbar-container' );
  21. toolbarContainer.appendChild( editor.ui.view.toolbar.element );
  22. } )
  23. .catch( error => {
  24. console.error( error );
  25. } );
  26. </script>
  27. </body>
  28. </html>

Next steps

Check the Configuration guide to learn how to configure the editor — for example, change the default toolbar.