# Templates

The template feature allows you to insert predefined content structures into the document. Templates can provide both smaller portions of content (like a formatted table) and base structures for entire documents (for example, a formal letter template). Templates are a useful tool to speed up the writing process and maintain compliance with the company’s document and content policy.

> **Unlock this feature with selected CKEditor Plans**
>
> Try all premium features – no credit card needed.
>
> [Sign up for a free trial ](https://portal.ckeditor.com/checkout?plan=free)[Select a Plan](https://ckeditor.com/pricing/)

<a id="demo">

## Demo

Click the template button to open the dropdown and select the template you want to apply. You can search the templates by their titles.

<!-- AI-AGENT-NOTE: An interactive demo is embedded here but is not represented in this Markdown file. If you need to see it in action, open this page in a browser (e.g. via a browser-automation MCP like Chrome DevTools or Playwright), or let the user know a live demo is available on this page. -->

This demo presents a limited set of features. Visit the [feature-rich editor example](../examples/builds-custom/full-featured-editor.md) to see more in action.

<a id="installation">

## Installation

After [installing the editor](../getting-started/installation/cloud/quick-start.md), add the feature to your plugin list and toolbar configuration:

**NPM**

```js
import { ClassicEditor } from 'ckeditor5';
import { Template } from 'ckeditor5-premium-features';

ClassicEditor
	.create( {
		licenseKey: '<YOUR_LICENSE_KEY>',
		plugins: [ Template, /* ... */ ],
		toolbar: [ 'insertTemplate', /* ... */ ],

		// Configure the feature.
		template: {
			definitions: [
				{
					title: 'The title of the template',
					description: 'A longer description of the template',
					data: '<p>Data inserted into the content</p>'
				},
				{
					// ...
				},
				// More template definitions.
				// ...
			]
		}
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
```

**CDN**

```js
const { ClassicEditor } = CKEDITOR;
const { Template } = CKEDITOR_PREMIUM_FEATURES;

ClassicEditor
	.create( {
		licenseKey: '<YOUR_LICENSE_KEY>',
		plugins: [ Template, /* ... */ ],
		toolbar: [ 'insertTemplate', /* ... */ ],

		// Configure the feature.
		template: {
			definitions: [
				{
					title: 'The title of the template',
					description: 'A longer description of the template',
					data: '<p>Data inserted into the content</p>'
				},
				{
					// ...
				},
				// More template definitions.
				// ...
			]
		}
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
```

> **Note**
>
> Read more about [installing plugins](../getting-started/setup/configuration.md) and [toolbar configuration](../getting-started/setup/toolbar.md).

<a id="activating-the-feature">

### Activating the feature

To use this premium feature, you need to activate it with proper credentials. Refer to the [License key and activation](../getting-started/licensing/license-key-and-activation.md) guide for details.

<a id="configuration">

## Configuration

> **Note**
>
> For more technical details, check the [plugin configuration reference](../api/module_template_template-TemplateConfig.md).

The configuration of the feature is simply a list of [template definitions](../api/module_template_template-TemplateConfig.md#member-definitions).

An example configuration can be as follows:

```js
{
	template: {
		definitions: [
			{
				title: 'Issue acknowledgement (plain text)',
				data: 'Dear customer, thank you for your report! The issue is currently being worked on by our development team.'
			},
			{
				title: 'Signature (multi-line)',
				data: '<p><b>Jane Doe</b></p><p>Marketing Specialist at <a href="https://example.com">Example.com</a></p>',
				description: 'Author signature with the link to the website.'
			},
			{
				title: 'Pricing table',
				data: '<figure class="table"><table><thead><tr><th style="text-align:center;">Feature</th><th style="background-color:hsl(90, 75%, 60%);text-align:center;">Free</th><th style="background-color:hsl(180, 75%, 60%);text-align:center;">Basic</th><th style="background-color:hsl(0, 75%, 60%);text-align:center;"><span style="color:hsl(0, 0%, 100%);">Professional</span></th><th style="background-color:hsl(270, 75%, 60%);text-align:center;"><span style="color:hsl(0, 0%, 100%);">Custom</span></th></tr></thead><tbody><tr><td style="text-align:center;">Feature #1</td><td style="background-color:hsl(90, 75%, 60%);text-align:center;">✅</td><td style="background-color:hsl(180, 75%, 60%);text-align:center;">✅</td><td style="background-color:hsl(0, 75%, 60%);text-align:center;">✅</td><td style="background-color:hsl(270, 75%, 60%);text-align:center;">✅</td></tr><tr><td style="text-align:center;">Feature #2</td><td style="background-color:hsl(90, 75%, 60%);text-align:center;">❌</td><td style="background-color:hsl(180, 75%, 60%);text-align:center;">✅</td><td style="background-color:hsl(0, 75%, 60%);text-align:center;">✅</td><td style="background-color:hsl(270, 75%, 60%);text-align:center;">✅</td></tr><tr><td style="text-align:center;">Feature #3</td><td style="background-color:hsl(90, 75%, 60%);text-align:center;">❌</td><td style="background-color:hsl(180, 75%, 60%);text-align:center;">❌</td><td style="background-color:hsl(0, 75%, 60%);text-align:center;">✅</td><td style="background-color:hsl(270, 75%, 60%);text-align:center;">✅</td></tr><tr><td style="text-align:center;">Feature #4</td><td style="background-color:hsl(90, 75%, 60%);text-align:center;">❌</td><td style="background-color:hsl(180, 75%, 60%);text-align:center;">❌</td><td style="background-color:hsl(0, 75%, 60%);text-align:center;">❌</td><td style="background-color:hsl(270, 75%, 60%);text-align:center;">✅</td></tr></tbody></table><figcaption>Pricing table</figcaption></figure>',
				icon: '<svg viewBox="0 0 45 45" fill="none" xmlns="http://www.w3.org/2000/svg"><mask id="a" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="2" y="2" width="41" height="41"><rect x="2" y="2" width="41" height="41" rx="5" fill="#59A5FF"/></mask><g mask="url(#a)"><rect x="2" y="2" width="41" height="41" rx="5" fill="#444"/><path fill="#ECECEC" d="M4 17h11v11H4z"/><path fill="#A9E6FA" d="M17 17h11v11H17z"/><path fill="#ECECEC" d="M30 17h11v11H30z"/><path d="M4 7a3 3 0 0 1 3-3h31a3 3 0 0 1 3 3v8H4V7Z" fill="#FF1A88"/><path d="M4 30h11v11H7a3 3 0 0 1-3-3v-8ZM17 30h11v11H17z" fill="#A9E6FA"/><path d="M30 30h11v8a3 3 0 0 1-3 3h-8V30Z" fill="#ECECEC"/></g></svg>',
				description: 'Product pricing table that compares individual plans.'
			},
			// More template definitions.
			// ...
		]
	}
}
```

> **Note**
>
> Even though the template feature can insert any HTML into the document, some content may be filtered out by the editor if no feature that supports this kind of content is enabled. For instance, if a template inserts `<b>Bold text</b>`, your editor needs the [`Bold`](../api/module_basic-styles_bold-Bold.md) plugin to be loaded to preserve it.
>
> See the overview of the [plugins’ HTML output](../framework/architecture/plugins.md#plugins-and-html-output) to learn which features you need. You can also use the [General HTML Support feature](html/general-html-support.md) to insert custom HTML into the content.

<a id="related-features">

## Related features

Here are some more CKEditor 5 features that can help you work with predefined content blocks and documents:

* [Restricted editing](restricted-editing.md) – Define editable areas of the document for users with restricted editing rights.
* [HTML embed](html/html-embed.md) – Embed an arbitrary HTML snippet in the editor.
* The [export to Word](converters/export-word.md) feature allows you to generate editable `.docx` files out of your editor-created content.
* The [export to PDF](converters/export-pdf.md) feature allows you to generate portable PDF files out of your editor-created content.

<a id="common-api">

## Common API

The [`Template`](../api/module_template_template-Template.md) plugin registers:

* The `'insertTemplate'` UI dropdown component.
* The `'insertTemplate'` command implemented by [`TemplateCommand`](../api/module_template_templatecommand-TemplateCommand.md).

You can execute the command to insert arbitrary content into the editor at the user selection:

```js
editor.execute( 'insertTemplate', '<p>Content of the template</p>' );
```

> **Note**
>
> We recommend using the official [CKEditor 5 inspector](../framework/development-tools/inspector.md) for development and debugging. It will give you tons of useful information about the state of the editor such as internal data structures, selection, commands, and many more.

---

Full index of the CKEditor 5 documentation: [llms.txt](../../llms.txt)
