Sign up (with export icon)

Integrating CKEditor 5 with Angular from CDN

Contribute to this guideShow the table of contents

CKEditor 5 has an official Angular component that you can use to add a rich text editor to your application, whether you use standalone or NGModule components. It works with multiple editor types, including classic, inline, and decoupled (document), and integrates with Angular forms through ngModel. This guide will help you install and configure it using the CDN distribution of CKEditor 5.

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

Quick start

Copy link

This guide assumes you already have an Angular project. To create such a project, you can use Angular CLI. Refer to the Angular documentation to learn more.

Note

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

First, install the CKEditor 5 WYSIWYG editor component for Angular:

npm install @ckeditor/ckeditor5-angular
Copy code

Angular is a TypeScript-first environment, so you may need to import TypeScript types for CKEditor. Depending on the plugins and features you use, you may also need to install the required open-source and premium packages:

npm install --save-dev ckeditor5 # Open-source plugin types.
npm install --save-dev ckeditor5-premium-features # Premium features plugin types.
Copy code

In the below example, the loadCKEditorCloud helper is used to load the editor code and plugins from CDN. To use CKEditor 5 with CDN, you need to import the function and call it inside the ngOnInit lifecycle hook with the version provided in the configuration. To use premium plugins, set the premium property to true and provide your license key in the configuration. For more information about the loadCKEditorCloud helper, see the Loading CDN resources guide.

// app.component.ts

import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CKEditorModule, loadCKEditorCloud, CKEditorCloudResult } from '@ckeditor/ckeditor5-angular';
import type { ClassicEditor, EditorConfig } from 'https://cdn.ckeditor.com/typings/ckeditor5.d.ts';

@Component( {
	selector: 'app-root',
	templateUrl: './app.component.html',
	styleUrls: ['./app.component.css'],
	imports: [ CommonModule, CKEditorModule ],
	standalone: true
} )
export class AppComponent {
	public Editor: typeof ClassicEditor | null = null;

	public config: EditorConfig | null = null;

	public ngOnInit(): void {
		loadCKEditorCloud( {
			version: '49.0.0',
			premium: true
		} ).then( this._setupEditor.bind( this ) );
	}

	private _setupEditor ( cloud: CKEditorCloudResult<{ version: '49.0.0', premium: true }> ) {
		const {
			ClassicEditor,
			Essentials,
			Paragraph,
			Bold,
			Italic
		} = cloud.CKEditor;

		const { FormatPainter } = cloud.CKEditorPremiumFeatures;

		this.Editor = ClassicEditor;
		this.config = {
			licenseKey: '<YOUR_LICENSE_KEY>',
			plugins: [ Essentials, Paragraph, Bold, Italic, FormatPainter ],
			toolbar: [ 'undo', 'redo', '|', 'bold', 'italic', '|', 'formatPainter' ]
		};
	}
}
Copy code

In the example above, the EditorConfig type is imported from the https://cdn.ckeditor.com/typings/ckeditor5.d.ts package, while the editor itself loads from the CDN. Note that https://cdn.ckeditor.com/typings/ckeditor5.d.ts is not an actual URL to the CKEditor 5 typings file but a synthetic TypeScript module providing type definitions for the editor. The ckeditor5 or ckeditor5-premium-features packages supply the actual types, which depend on the @ckeditor/ckeditor5-angular package.

Finally, use the <ckeditor> tag in the template to run the rich text editor. The usage is the same regardless of the plugin configuration.

<!-- app.component.html -->

<ckeditor
	*ngIf="( Editor && config )"
	data="<p>Hello, world!</p>"
	[editor]="Editor"
	[config]="config"
>
</ckeditor>
Copy code

Supported @Input properties

Copy link

The following @Input properties are supported by the CKEditor 5 rich text editor component for Angular:

editor (required)

Copy link

The Editor which provides the static create() method to create an instance of the editor:

<ckeditor [editor]="Editor"></ckeditor>
Copy code

config

Copy link

The configuration of the editor:

<ckeditor [config]="{ toolbar: [ 'heading', '|', 'bold', 'italic' ] }"></ckeditor>
Copy code

data

Copy link

The initial data of the editor. It can be a static value:

<ckeditor data="<p>Hello, world!</p>"></ckeditor>
Copy code

or a shared parent component’s property

@Component( {
	// ...
} )
export class MyComponent {
	public editorData;

	private _setupEditor( cloud ) {
		this.editorData = '<p>Hello, world!</p>';
	}
	// ...
}
Copy code
<ckeditor [data]="editorData"></ckeditor>
Copy code

tagName

Copy link

The tag name of the HTML element on which the rich text editor will be created.

The default tag is <div>.

<ckeditor tagName="textarea"></ckeditor>
Copy code

disabled

Copy link

Controls the editor’s read–only state:

@Component( {
	// ...
} )
export class MyComponent {
	public isDisabled;
	// ...
	private _setupEditor( cloud ) {
		this.isDisabled = false;
	}
	toggleDisabled() {
		this.isDisabled = !this.isDisabled;
	}
}
Copy code
<ckeditor [disabled]="isDisabled"></ckeditor>

<button (click)="toggleDisabled()">
	{{ isDisabled ? 'Enable editor' : 'Disable editor' }}
</button>
Copy code

disableTwoWayDataBinding

Copy link

Allows disabling the two-way data binding mechanism. The default value is false.

The reason for the introduction of this option is performance issues in large documents. By default, while using the ngModel directive, whenever the editor’s data is changed, the component must synchronize the data between the editor instance and the connected property. This results in calling the editor.getData() function, which causes a massive slowdown while typing in large documents.

This option allows the integrator to disable the default behavior and only call the editor.getData() method on demand, which prevents the slowdowns. You can read more in the relevant issue.

Supported @Output properties

Copy link

The following @Output properties are supported by the CKEditor 5 rich text editor component for Angular:

ready

Copy link

Fired when the editor is ready. It corresponds with the editor#ready event.
It is fired with the editor instance.

change

Copy link

Fired when the content of the editor has changed. It corresponds with the editor.model.document#change:data event.
It is fired with an object containing the editor and the CKEditor 5 change:data event object.

<ckeditor [editor]="Editor" (change)="onChange($event)"></ckeditor>
Copy code
import { ClassicEditor } from 'ckeditor5';
import { ChangeEvent } from '@ckeditor/ckeditor5-angular/ckeditor.component';

@Component( {
	// ...
} )
export class MyComponent {
	public Editor;

	private _setupEditor( cloud ) {
		const {
			ClassicEditor
		} = cloud.CKEditor;

		this.Editor = ClassicEditor;
	}

	public onChange( { editor }: ChangeEvent ) {
		const data = editor.getData();

		console.log( data );
	}
	// ...
}
Copy code

blur

Copy link

Fired when the editing view of the editor is blurred. It corresponds with the editor.editing.view.document#blur event.
It is fired with an object containing the editor and the CKEditor 5 blur event data.

focus

Copy link

Fired when the editing view of the editor is focused. It corresponds with the editor.editing.view.document#focus event.
It is fired with an object containing the editor and the CKEditor 5 focus event data.

error

Copy link

Fired when an error is reported for the editor, either during the initialization or at runtime.

Note

Prior to ckeditor5-angular v7.0.1, this event was not fired for errors during the editor initialization.

A reported error does not stop the editor. Its state may no longer be consistent, so do not leave the error unhandled. Nothing is restarted and no data is restored for you, so what happens next is your application’s decision.

The error handling guide covers the options: telling the user and switching the editor to read-only, recreating it, and recovering its content. If you are moving off the Watchdog, the migrating from the Watchdog guide shows how to recreate the editor and when to do it. In Angular that check differs from the other integrations because the error output carries no phase.

Integration with ngModel

Copy link

The component implements the ControlValueAccessor interface and works with the ngModel. Here is how to use it:

Create some model in your component to share with the editor:

@Component( {
	// ...
} )
export class MyComponent {
	public model;

	private _setupEditor( cloud ) {
		this.model = {
			editorData: '<p>Hello, world!</p>'
		};
	}
	// ...
}
Copy code

Use the model in the template to enable a two–way data binding:

<ckeditor [(ngModel)]="model.editorData" [editor]="Editor"></ckeditor>
Copy code

Styling

Copy link

The CKEditor 5 rich text editor component for Angular can be styled using the component style sheet or using a global style sheet. See how to set the CKEditor 5 component’s height using these two approaches.

Setting the height via the component style sheet

Copy link

First, create a (S)CSS file in the parent component’s directory and style the given editor’s part preceded by the :host and ::ng-deep pseudo selectors:

/* src/app/app.component.css */

:host ::ng-deep .ck-editor__editable_inline {
	min-height: 500px;
}
Copy code

Then, in the parent component, add the relative path to the above style sheet:

/* src/app/app.component.ts */

@Component( {
	// ...
	styleUrls: [ './app.component.css' ]
} )
Copy code

Setting the height via a global style sheet

Copy link

To style the component using a global style sheet, first, create it:

/* src/styles.css */

.ck-editor__editable_inline {
	min-height: 500px;
}
Copy code

Then, add it to the angular.json configuration file:

"architect": {
	"build": {
		"options": {
			"styles": [
				{ "input": "src/styles.css" }
			]
		}
	}
}
Copy code

Setting the placeholder

Copy link

To display the placeholder in the main editable element, set the root.placeholder field in the CKEditor 5 rich text editor component configuration:

@Component( {
	// ...
} )
export class MyComponent {
	public config;

	private _setupEditor( cloud ) {
		// ...
		this.config = {
			root: {
				placeholder: 'Type the content here!'
			}
		}
	}

}
Copy code

Accessing the editor instance

Copy link

The CKEditor 5 rich text editor component provides all the functionality needed for most use cases. When access to the full CKEditor 5 API is needed, you can get the editor instance with an additional step.

To do this, create a template reference variable #editor pointing to the <ckeditor> component:

<ckeditor #editor [editor]="Editor"></ckeditor>
Copy code

Then get the <ckeditor> component using a property decorated by @ViewChild( 'editor' ) and access the editor instance when needed:

@Component()
export class MyComponent {
	@ViewChild( 'editor' ) editorComponent: CKEditorComponent;

	public getEditor() {
		// Warning: This may return "undefined" if the editor is hidden behind the `*ngIf` directive or
		// if the editor is not fully initialised yet.
		return this.editorComponent.editorInstance;
	}
}
Copy code
Note

The editor creation is asynchronous, so the editorInstance will not be available until the editor is created. If you want to make changes to an editor that has just been created, a better option would be getting the CKEditor 5 instance on the ready event.

How to?

Copy link

Using the Document editor type

Copy link

If you want to use the document (decoupled) editor, you need to add the toolbar to the DOM manually:

// app.component.ts

import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CKEditorCloudResult, CKEditorModule, loadCKEditorCloud } from '@ckeditor/ckeditor5-angular';
import { DecoupledEditor, EditorConfig } from 'https://cdn.ckeditor.com/typings/ckeditor5.d.ts';

@Component( {
	selector: 'app-root',
	templateUrl: './app.component.html',
	styleUrls: [ './app.component.css' ],
	imports: [ CommonModule, CKEditorModule ],
	standalone: true
} )
export class AppComponent {
	title = 'angular';

	public Editor: typeof DecoupledEditor | null = null;

	public config: EditorConfig | null = null;

	public ngOnInit(): void {
		loadCKEditorCloud( {
			version: '49.0.0'
		} ).then( this._setupEditor.bind( this ) );
	}

	private _setupEditor( cloud: CKEditorCloudResult<{ version: '49.0.0'}>) {
		const {
			DecoupledEditor,
			Essentials,
			Paragraph,
			Bold,
			Italic
		} = cloud.CKEditor;

		this.Editor = DecoupledEditor;
		this.config = {
			licenseKey: '<YOUR_LICENSE_KEY>',
			plugins: [ Essentials, Paragraph, Bold, Italic ],
			toolbar: [ 'undo', 'redo', '|', 'bold', 'italic' ]
		};
	}

	public onReady( editor: DecoupledEditor ) {
		const element = editor.ui.getEditableElement()!;
		const parent = element.parentElement!;

		parent.insertBefore(
			editor.ui.view.toolbar.element!,
			element
		);
	}
}
Copy code

And then, link the method in the template:

<!-- app.component.html -->

<ckeditor
  *ngIf="(Editor && config)"
  data="<p>Hello, world!</p>"
  [editor]="Editor"
  [config]="config"
  (ready)="onReady($event)"
>
</ckeditor>
Copy code

Using an inline editor

Copy link

Single-root editors such as InlineEditor, BalloonEditor, and DecoupledEditor can be configured as inline editors that accept only inline content (text, bold, italic, links) instead of blocks. This is useful for short fields such as titles, captions, or single-line inputs.

Set root.modelElement to '$inlineRoot' to restrict the root to inline content. Optionally, provide a custom root.element to render the editable host as a specific tag (for example, <h1> for a title) instead of the default <div>.

// app.component.ts

import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CKEditorCloudResult, CKEditorModule, loadCKEditorCloud } from '@ckeditor/ckeditor5-angular';
import { BalloonEditor, EditorConfig } from 'https://cdn.ckeditor.com/typings/ckeditor5.d.ts';

@Component( {
	selector: 'app-root',
	templateUrl: './app.component.html',
	imports: [ CommonModule, CKEditorModule ],
	standalone: true
} )
export class AppComponent {
	public Editor: typeof BalloonEditor | null = null;

	public config: EditorConfig | null = null;

	public ngOnInit(): void {
		loadCKEditorCloud( {
			version: '49.0.0'
		} ).then( this._setupEditor.bind( this ) );
	}

	private _setupEditor( cloud: CKEditorCloudResult<{ version: '49.0.0' }> ) {
		const { BalloonEditor, Essentials, Bold, Italic } = cloud.CKEditor;

		this.Editor = BalloonEditor;
		this.config = {
			licenseKey: '<YOUR_LICENSE_KEY>',
			plugins: [ Essentials, Bold, Italic ],
			toolbar: [ 'bold', 'italic' ],
			root: {
				element: 'h1',
				modelElement: '$inlineRoot',
				initialData: 'Document title',
				placeholder: 'Enter title...'
			}
		};
	}
}
Copy code
<!-- app.component.html -->

<ckeditor
  *ngIf="(Editor && config)"
  [editor]="Editor"
  [config]="config"
></ckeditor>
Copy code

The root.element property accepts:

  • A tag name string, for example 'h1' or 'section'.
  • A descriptor object with name, classes, styles, and attributes fields.

Without modelElement: '$inlineRoot', only the host tag changes – the schema still permits blocks inside the root.

Using inside a shadow root

Copy link

Rendering the editor inside a shadow root isolates it from the styles of the host page. Set ViewEncapsulation.ShadowDom on the component and Angular attaches the root for you. Use a component that wraps the editor rather than the root component of the application, or everything the application renders ends up inside the root.

The loader injects the editor style sheets as <link> tags, so point it at that root with the injectedStylesheetsLocation option. Without it they would land in document.head, which the shadow root cannot see. The whole editor UI, including the body collection that holds balloons and dropdown panels, stays inside the shadow root, so the scoped style sheets cover all of it. This happens because config.ui.overlayContainer is not set, so the editor falls back to the root it is in and logs the ui-overlay-container-not-configured warning. For a more robust setup, set your own overlay container and load the same style sheets into it, as described in the Where the floating user interface mounts section of the Shadow DOM guide.

// editor.component.ts

import { Component, ElementRef, ViewEncapsulation, inject, type AfterViewInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CKEditorCloudResult, CKEditorModule, loadCKEditorCloud } from '@ckeditor/ckeditor5-angular';
import { ClassicEditor, EditorConfig } from 'https://cdn.ckeditor.com/typings/ckeditor5.d.ts';

@Component( {
	selector: 'app-editor',
	templateUrl: './editor.component.html',
	imports: [ CommonModule, CKEditorModule ],
	standalone: true,
	encapsulation: ViewEncapsulation.ShadowDom
} )
export class EditorComponent implements AfterViewInit {
	public Editor: typeof ClassicEditor | null = null;

	public config: EditorConfig | null = null;

	private readonly _elementRef: ElementRef<HTMLElement> = inject( ElementRef );

	// Loading starts after the view is initialized, so that the shadow root is already in the
	// document. A `<link>` in a detached tree never starts loading, and the loader would wait for it.
	public ngAfterViewInit(): void {
		loadCKEditorCloud( {
			version: '49.0.0',
			injectedStylesheetsLocation: {
				targetNode: this._elementRef.nativeElement.shadowRoot!
			}
		} ).then( this._setupEditor.bind( this ) );
	}

	private _setupEditor( cloud: CKEditorCloudResult<{ version: '49.0.0' }> ) {
		const { ClassicEditor, Essentials, Paragraph, Bold, Italic } = cloud.CKEditor;

		this.Editor = ClassicEditor;
		this.config = {
			licenseKey: '<YOUR_LICENSE_KEY>',
			plugins: [ Essentials, Paragraph, Bold, Italic ],
			toolbar: [ 'bold', 'italic' ]
		};
	}
}
Copy code
<!-- editor.component.html -->

<ckeditor
  *ngIf="(Editor && config)"
  data="<p>Hello, world!</p>"
  [editor]="Editor"
  [config]="config"
></ckeditor>
Copy code

An override of a --ck-* variable on :root has no effect on an editor inside a shadow root, so put it on the shadow host instead. The Shadow DOM guide explains why, and covers the known limitations.

Using the editor with collaboration plugins

Copy link

We provide ready-to-use integration featuring collaborative editing in an Angular application:

It is not mandatory to build an application on top of the above samples, however, it should help you get started.

Sharing a context

Copy link

To share one Context between editors, create it yourself and pass it in the editor configuration:

this.context = await MyEditor.Context.create( {
	// The context configuration.
} );

this.config = { context: this.context };
Copy code

The context is yours, so destroy it when you are done with it.

Hold the editors back until the context is ready, with *ngIf="config" on the <ckeditor> element. The component reads its configuration only once, when it creates the editor. If it renders before Context.create() resolves, the editor gets no context, and setting the configuration later changes nothing. Errors attributed to the context rather than to one of its editors are not emitted by the component; register a callback for those with MyEditor.Context.onEditorError().

Localization

Copy link

CKEditor 5 supports multiple UI languages, and so does the official Angular component. To translate the editor, pass the languages you need into the translations array inside the configuration of the loadCKEditorCloud function.

import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CKEditorModule, loadCKEditorCloud, CKEditorCloudResult } from '@ckeditor/ckeditor5-angular';
import { ClassicEditor, EditorConfig } from 'https://cdn.ckeditor.com/typings/ckeditor5.d.ts';

@Component( {
	selector: 'app-root',
	templateUrl: './app.component.html',
	styleUrls: ['./app.component.css'],
	imports: [ CommonModule, CKEditorModule ],
	standalone: true
} )
export class AppComponent {
	public Editor: typeof ClassicEditor | null = null;

	public config: EditorConfig | null = null;

	public ngOnInit(): void {
		loadCKEditorCloud( {
			version: '49.0.0',
			translations: [ 'es' ]
		} ).then( this._setupEditor.bind( this ) );
	}

	private _setupEditor ( cloud: CKEditorCloudResult<{ version: '49.0.0'}> ) {
		const {
			ClassicEditor,
			Paragraph,
			Essentials,
			Bold,
			Italic
		} = cloud.CKEditor;

		this.Editor = ClassicEditor;
		this.config = {
			licenseKey: '<YOUR_LICENSE_KEY>',
			plugins: [ Essentials, Bold, Italic, Paragraph ],
			toolbar: [ 'undo', 'redo', '|', 'bold', 'italic' ]
		};
	}
}
Copy code

Supported Angular versions

Copy link
Note

Starting from version 6.0.0 of this package, you can use native type definitions provided by CKEditor 5.

Because of the breaking changes in the Angular library output format, the @ckeditor/ckeditor5-angular package is released in the following versions to support various Angular ecosystems:

CKEditor 5  Angular component version Angular version Details
Actively supported versions
^11 19+ Requires CKEditor 5 in version 47 or higher.
Past releases (no longer maintained)
^10 16+ Requires CKEditor 5 in version 46 or higher.
^9 16+ Migration to TypeScript 5. Declaration files are not backward compatible. Requires CKEditor 5 in version 43 or higher.
^8 13+ Requires CKEditor 5 in version 42 or higher.
^7 13+ Changes in peer dependencies (issue). Requires CKEditor 5 in version 37 or higher.
^6 13+ Requires CKEditor 5 in version 37 or higher.
^5 13+ Requires Angular in version 13+ or higher.
^4 9.1+ Requires CKEditor 5 in version 34 or higher.
^3 9.1+ Requires Node.js in version 14 or higher.
^2 9.1+ Migration to TypeScript 4. Declaration files are not backward compatible.
^1 5.x - 8.x Angular versions no longer maintained.

All available Angular versions are listed on npm, where they can be pulled from.

Contributing and reporting issues

Copy link

The source code of the CKEditor 5 rich text editor component for Angular is available on GitHub at https://github.com/ckeditor/ckeditor5-angular.

Next steps

Copy link