# Export to Word

The export to Word feature lets you generate a `.docx` file directly from the editor. It sends the editor’s content and styles to the CKEditor Cloud Services HTML-to-DOCX converter, so the Word file preserves the document’s formatting.

> **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

The demo below lets you generate a Word file based on the editor’s content. Edit the document, then click the export to Word toolbar button to save the content as a Word file.

<!-- 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.

> **Note**
>
> If you have already tried the export to Word feature, **help us develop it by sharing your feedback** with [this short survey](https://www.surveymonkey.com/r/ZYJBCZT). It only takes about 2 minutes, but will be invaluable for the development team. Thank you!

<a id="how-it-works">

## How it works

The export to Microsoft Word feature collects the HTML generated with the [`editor.getData()`](../../api/module_editor-classic_classiceditor-ClassicEditor.md#function-getData) method and the [default editor content styles](../../getting-started/setup/css.md) combined with the styles provided by you in the configuration. It then sends them to the CKEditor Cloud Services HTML to DOCX converter service. The service generates a Word file and returns it to the user’s browser so they can save it in the Word format on their disk.\
You can read more about the converter and the plugin in a [dedicated Feature spotlight blog post](https://ckeditor.com/blog/feature-spotlight-html-to-word-converter/).

> **Note**
>
> The generated `.docx` file may not be fully compatible with older versions of Word. At the time of writing this guide, the generated document was fully compatible with Word in Office 365.

You can use the complementary [pagination feature](../pagination/pagination.md) to see where page breaks would be (after exporting your document to Word). However, due to the nature of Word page rendering, the results may be inconsistent (read more about [known issues](../pagination/pagination.md#automatic-page-breaks-in-export-to-word)). You can force the page breaks from pagination in Word by enabling the [`auto_pagination: true`](../../api/module_export-word_exportword-ExportWordConverterOptions.md#member-auto_pagination) configuration option. You can also fine-tune the structure of the output document by using live preview. The pagination feature also shows the page count and lets you navigate between the document pages.

<a id="integration-with-merge-fields-content-placeholders">

## Integration with merge fields (content placeholders)

[Merge fields](../merge-fields.md) are visually distinct placeholder elements you can put into the content to mark places where real values should be inserted. They are perfect for creating document templates and other kinds of personalized content. This allows for automation and creating batch output of personalized `.docx` files. Learn how to configure it in the [Export to Word merge fields](../../../../cs/latest/guides/export-to-word/merge-fields.md) guide.

<a id="before-you-start">

## Before you start

> **Note**
>
> On the Free Plan, file conversion is available in a limited capacity. Unlock significantly more conversions and full access with a [CKEditor Paid Plan](https://ckeditor.com/pricing/).
>
> You can also sign up for the [CKEditor Premium Features 14-day free trial](https://portal.ckeditor.com/checkout?plan=free) to test the feature.

After you select a plan, follow the steps below, as explained in the [Export to Word quick start guide](../../../../cs/latest/guides/export-to-word/quick-start.md):

* [Log into the CKEditor Ecosystem customer dashboard](../../../../cs/latest/guides/export-to-word/quick-start.md#log-in-to-the-customer-portal).
* [Create the token endpoint needed for authorization](../../../../cs/latest/guides/export-to-word/quick-start.md#creating-token-endpoint).
* [Install](#installation) and [configure](#configuration) the CKEditor 5 export to Word plugin.

<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 { ExportWord } from 'ckeditor5-premium-features';

ClassicEditor
	.create( {
		licenseKey: '<YOUR_LICENSE_KEY>',
		plugins: [ ExportWord, /* ... */ ],
		toolbar: [ 'exportWord', '|', /* ... */ ],
		exportWord: {
			// Configuration.
		}
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
```

**CDN**

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

ClassicEditor
	.create( {
		licenseKey: '<YOUR_LICENSE_KEY>',
		plugins: [ ExportWord, /* ... */ ],
		toolbar: [ 'exportWord', '|', /* ... */ ],
		exportWord: {
			// Configuration.
		}
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
```

<a id="configuration">

## Configuration

> **Note**
>
> For more technical details, check the [plugin configuration API](../../api/module_export-word_exportword-ExportWordConfig.md).

<a id="default-configuration">

### Default configuration

This is the default configuration of the Word export feature for CKEditor 5.

```js
{
	exportWord: {
		fileName: 'document.docx',
		converterUrl: 'https://docx-converter.cke-cs.com/v2/convert/html-docx',
		stylesheets: [
			'./ckeditor5-content.css'
		],
		converterOptions: {
			document: {
				size: 'A4',
				orientation: 'portrait',
				margin: {
					top: '1in',
					bottom: '1in',
					right: '1in',
					left: '1in',
				},
				language: 'en' // By default it is set to editor content language.
			},
		},
		dataCallback: ( editor ) => editor.getData( { pagination: true } )
	}
}
```

If you are using the EU cloud region, remember to adjust the endpoint:

```js
exportWord: {
	converterUrl: 'https://docx-converter.cke-cs-eu.com/v2/convert/html-docx'
}
```

<a id="stylesheets-option">

### `stylesheets` option

Use the `stylesheets` option to provide paths (relative or absolute URLs) to all style sheets that should be included during the HTML to DOCX conversion.

The rule of thumb is if you want the export to preserve the styles, always add the style sheets with the content styles of the editor. Their path depends on your application setup, for example:

```js
{
	exportWord: {
		stylesheets: [
			'./ckeditor5-content.css',
			'./styles.css'
		],
		// ...
	}
}
```

In the snippet above, we assume both style sheets are available via the relative path on the client side. For example, some frameworks allow to place files in the `public` folder.

<a id="plugin-options">

### Plugin options

For some use cases the default configuration will suffice. As you can see in the example above, you can improve how your Word file will look by adjusting the Word export plugin configuration.

* **[`config.exportWord.stylesheets`](../../api/module_export-word_exportword-ExportWordConfig.md#member-stylesheets)**

  You can set the paths (relative or absolute URLs) to the style sheets that should be included during the HTML to DOCX conversion.

  > **Warning**
  >
  > **The order of the paths matters**. If you have custom elements or have overridden the default editor’s content styles, the paths to your file(s) should go after the editor content styles. See the examples in the `config.exportWord.stylesheets` documentation.

* **[`config.exportWord.fileName`](../../api/module_export-word_exportword-ExportWordConfig.md#member-fileName)**

  Sets the name for the generated Word file (together with the extension). The default name is `document.docx`. You can see it called in the [default configuration](#default-configuration) listing above.

  This option, however, also allows for using a callback to generate a dynamic file name. In the example below, the document’s title will be used as the file name of the generated `.docx` file.

  ```js
  // Dynamic file name.
  const exportWordConfig = {
  	fileName: () => {
  		const articleTitle = document.querySelector( '#title' );
  		return `${ articleTitle.value }.docx`;
  	}
  }
  ```

* **[`config.exportWord.converterUrl`](../../api/module_export-word_exportword-ExportWordConfig.md#member-converterUrl)**

  By default, the Word export feature uses the CKEditor Cloud Services HTML to DOCX converter service to generate the Word files. You can use this option to provide the URL to an on-premises converter. [Contact us](https://ckeditor.com/contact/) if you need this feature.

* **[`config.exportWord.tokenUrl`](../../api/module_export-word_exportword-ExportWordConfig.md#member-tokenUrl)**

  A token URL or a token request function. This field is optional and you should use it when you require a different [`tokenUrl`](../../api/module_cloud-services_cloudservicesconfig-CloudServicesConfig.md#member-tokenUrl) for the export to Word feature. You can skip this option if you use the `cloudServices` configuration to provide the same `tokenUrl`. In most cases you will probably want to provide the token in `cloudServices`, as other plugins like [real-time collaboration](../collaboration/real-time-collaboration/real-time-collaboration.md) will use this token as well. In this guide, to explicitly show that this value is needed, we leave it inside the `exportWord` configuration.

* **[`config.exportWord.converterOptions`](../../api/module_export-word_exportword-ExportWordConfig.md#member-converterOptions)**

  The plugin allows you to provide a custom [CKEditor Cloud Services HTML to DOCX converter configuration](../../api/module_export-word_exportword-ExportWordConfig.md#member-converterOptions), such as paper size, orientation, or watermark. Below, you will find the options listed in a sample configuration:

  ```js
  converterOptions: {
  			document: {
  				size: 'A4',
  				margin: {
  					top: '20mm',
  					bottom: '20mm',
  					right: '12mm',
  					left: '12mm'
  				}
  			},
  			watermark: {
  				source: 'https://placehold.co/600x400/transparent/DDD?text=Watermark',
  				width: '600px',
  				height: '400px',
  				washout: 'true'
  			}
  		}
  ```

* **[`config.exportWord.dataCallback`](../../api/module_export-word_exportword-ExportWordConfig.md#member-dataCallback)**

  By default, the plugin uses `editor.getData( { pagination: true } )` to gather the HTML sent to the conversion service. You can use this option to customize the editor’s data.

  When using the [pagination](../pagination/pagination.md) feature, the `pagination:true` option inserts additional markers into the editor’s data. Thanks to that, the HTML to DOCX converter creates a Word document similar to what is displayed in the editor.

> **Note**
>
> The [`config.exportWord.dataCallback`](../../api/module_export-word_exportword-ExportWordConfig.md#member-dataCallback) option may be useful when handling:
>
> * The [multi-root editor](../../examples/builds/multi-root-editor.md).
> * The [track changes suggestions preview](../collaboration/track-changes/track-changes.md#saving-the-data-with-suggestion-highlights).

<a id="export-to-word-v1">

### Export to Word V1

**Note:** Export to Word uses the new version of the converter by default, the old one will no longer receive updates. It is highly recommended to migrate to the [latest version](https://docx-converter.cke-cs.com/v2/convert/docs). For more details on migrating from `v1` to `v2` see the [migration guide](https://docx-converter.cke-cs.com/v2/convert/docs#section/Export-to-Word/Migrating-from-v1). To use `v1`, you need to specify the version in the `version` property of the configuration, as shown in the snippet below.

```js
{
	exportWord: {
		// ...
		version: 1, // by default this is set to 2.
		converterOptions: {
			format: 'A4',
			orientation: 'portrait',
			margin_top: '1in',
			margin_bottom: '1in',
			margin_right: '1in',
			margin_left: '1in'
		},
		// ...
	}
}
```

View V1 headers and footers example

```js
// Let's keep the CSS string as a variable to avoid unnecessary string duplication.
const templateCSS = '.styled { color: #4b22aa; text-align: center; }'

const converterOptions = {
	header: [
		// Header template for all headers (without the `type` property).
		{ html: '<p class="styled">Default header content</p>', css: templateCSS },
		// Header template only for the first page of the document.
		{ html: '<p class="styled">First document page header content</p>', css: templateCSS, type: 'first' },
		// Header template for every even page of the document.
		{ html: '<p class="styled">Every even page header content</p>', css: templateCSS, type: 'even' },
		// Header template for every odd page of the document.
		{ html: '<p class="styled">Every odd page header content</p>', css: templateCSS, type: 'odd' }
	],
	footer: [
		// Footer template for all footers (without the `type` property).
		{ html: '<p class="styled">Default footer content</p>', css: templateCSS },
		// Footer template only for the first page of the document.
		{ html: '<p class="styled">First document page footer content</p>', css: templateCSS, type: 'first' },
		// Footer template for every even page of the document.
		{ html: '<p class="styled">Every even page footer content</p>', css: templateCSS, type: 'even' },
		// Footer template for every odd page of the document.
		{ html: '<p class="styled">Every odd page footer content</p>', css: templateCSS, type: 'odd' }
	],
}
```

<a id="html-to-word-converter-features">

## HTML to Word converter features

<a id="styling-a-document">

### Styling a document

By default, the [export to Word](../../api/module_export-word_exportword-ExportWord.md) plugin takes editor content styles and sends them to the CKEditor Cloud Services HTML to DOCX Converter. You can also add custom styles by providing the paths to the external CSS files.

```js
// More editor's configuration.
// ...
exportWord: {
	fileName: 'document.docx',
	converterUrl: 'https://docx-converter.cke-cs.com/v2/convert/html-docx',
	stylesheets: [
		'path/to/editor-styles.css',
		'path/to/my-styles.css'
	],
	// More configuration of the export to Word feature.
	// ...
}
// More editor's configuration.
// ...
```

<a id="supported-css-properties">

#### Supported CSS properties

The HTML to DOCX Converter supports proper CSS inheritance with a set of whitelisted properties. You can use them to style the document content.

You can apply CSS properties like:

* `color`
* `background-color`
* `font-size`
* `font-family`
* `text-align`

to the following elements: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `p`, `span`, `td`, `th`, `strong`, `i`, `u`, `s`, `sub`, `sup`, `mark`.

You can also position images using the `float` CSS property, supporting `left`, `right`, and `none` values.

> **Note**
>
> You can use any CSS selector to style these elements, including classes, attributes, and the `*` selector.

<a id="setting-the-page-format">

### Setting the page format

Consistency is an important factor. To make sure that the editor content and the generated Word file look the same, you need to match their format settings. You can change your existing style sheet or use a new one, for example, `format.css`. By default, the CKEditor Cloud Services HTML to DOCX converter is set to A4 format, but you may change this setting in your configuration.

Assuming that you want to create a document in the US Letter format, with the standard margins (`19mm` for each side), here is the example code you can use:

```js
ClassicEditor
	.create( {
		// ... Other configuration options ...
		exportWord: {
			stylesheets: [
				'path/to/editor-styles.css',
				'path/to/my-styles.css'
			],
			fileName: 'my-document.docx',
			converterOptions: {
				document: {
					size: 'Letter',
					// Document format settings with proper margins.
					margin: {
						top: '19mm',
						bottom: '19mm',
						right: '19mm',
						left: '19mm'
					}
				}
			}
		}
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
```

> **Note**
>
> This example focuses only on preparing the editable to match the converter settings. Please keep in mind that as a result, the appearance of your editor may change. Depending on your editor type and implementation or even some inherited global styles like `box-sizing`, applying new `padding` values may change the size of the editor on your website.
>
> For the purpose of this example, `box-sizing: border-box` was implemented to make sure that the editor’s width will not change.

Now set the corresponding editor styles:

```css
/* format.css */

/* Styles for the editable. */
.ck.ck-content.ck-editor__editable {
	/* US Letter size. */
	width: 215.9mm;
	/* Padding is your document's margin. */
	padding: 19mm;
	/* You don't want to change the size of the editor by applying the new padding values. */
	box-sizing: border-box;
	/* ... */
}
```

With these settings, the content in the generated Word file should have the same US Letter format layout as it has in the editor.

<a id="header-and-footer">

### Header and footer

The converter lets you set the document’s header and footer similarly to Microsoft Word or Google Docs.

```js
const templateCSS = '.styled { color: #4b22aa; text-align: center; }'

const converterOptions = {
	headers: {
		// Header template for all headers.
		default : {
			html: '<p class="styled">Default header content</p>',
			css: templateCSS
		},
		// Header template only for the first page of the document.
		first: {
			html: '<p class="styled">First document page header content</p>',
			css: templateCSS
		},
		// Header template for every even page of the document.
		even: {
			html: '<p class="styled">Every even page header content</p>',
			css: templateCSS
		},
		// Header template for every odd page of the document.
		odd: {
			html: '<p class="styled">Every odd page header content</p>',
			css: templateCSS
		}
	},
	footers: {
		// Footer template for all footers.
		default: {
			html: '<p class="styled">Default footer content</p>',
			css: templateCSS
		},
		// Footer template only for the first page of the document.
		first: {
			html: '<p class="styled">First document page footer content</p>',
			css: templateCSS
		},
		// Footer template for every even page of the document.
		even: {
			html: '<p class="styled">Every even page footer content</p>',
			css: templateCSS
		},
		// Footer template for every odd page of the document.
		odd: {
			html: '<p class="styled">Every odd page footer content</p>',
			css: templateCSS
		}
	},
}
```

Regarding CSS, you can style the `headers` and `footers` using the same [supported properties](#supported-css-properties) as used for styling the whole document.

For more details, refer to the [CKEditor Cloud Services HTML to DOCX converter’s documentation](https://docx-converter.cke-cs.com/v2/convert/docs).

As you can see, the `headers` and `footers` options are objects whose keys (`default`, `first`, `even`, and `odd`) define the template for each page type. If you want a consistent template no matter the page, define only the `default` entry.

If you import headers and footers from a Word document and want to preserve and reapply them when exporting, see the [preserving headers and footers](import-word/import-word.md#preserving-headers-and-footers) section in the [Import from Word](import-word/import-word.md) guide.

<a id="setting-the-base-url">

### Setting the base URL

To enable proper resolution of relative URLs for images and links, you need to pass the `base_url` option:

```js
const conversionOptions = {
	base_url: 'https://ckeditor.com'
};
```

For an editor’s content like the one below:

```html
<p><a href="/">Our company homepage</a></p>
<p><img src="/logo.svg" alt="Our logo"></p>
```

this option will result in resolving these URLs into their absolute forms:

* `/` will become `https://ckeditor.com`,
* `/logo.svg` will become `https://ckeditor.com/logo.svg`.

<a id="adding-a-watermark">

### Adding a watermark

The Export to Word converter allows for easy adding a graphic watermark via the [`converterOptions`](../../api/module_export-word_exportword-ExportWordConfig.md#member-converterOptions) configuration setting.

The watermark configuration is represented as an object containing 4 properties:

* `source`: A source of the image used for the watermark.
* `width`: A string value representing the width of the watermark.
* `height`: A string value representing the height of the watermark.
* `washout`: Determines whether the washout effect should be applied. Optional - the default value is `false`.

```js
converterOptions: {
		watermark: {
			source: 'https://placehold.co/600x400/EEE/31343C',
			width: '600px',
			height: '400px',
			washout: 'true'
		}
	}
```

<a id="comments-and-suggestions">

### Comments and suggestions

When your editor has [collaboration features](https://ckeditor.com/collaboration/) (like comments and track changes) enabled, the [export to Word](../../api/module_export-word_exportword-ExportWord.md) feature will take care of setting the configuration needed by the CKEditor Cloud Services HTML to DOCX converter. But if for some reason you need to pass your own data, you can do this via the [REST API converter options](https://docx-converter.cke-cs.com/v2/convert/docs).

> **Note**
>
> Currently formatting suggestions are not supported. Only insertions and deletions will work correctly with the CKEditor Cloud Services HTML to DOCX converter.

<a id="other">

### Other

* By default, the generated Word file is encoded with **`UTF-8`**.

<a id="known-issues">

## Known issues

Not all CKEditor 5 plugins and features are compatible with export to Word at the moment. Feel free to [contact us](https://ckeditor.com/contact/) if you are interested in any of these features specifically. Here is a list of known issues:

<a id="automatic-page-breaks-with-the-pagination-feature">

### Automatic page breaks with the pagination feature

Browser engines and Microsoft Word differ significantly. Because of that, the automatic prediction of page breaks provided by the [pagination feature](../pagination/pagination.md) in [Export to Word](export-word.md) is problematic and error-prone. We recommend reviewing your document’s structure during the exporting and manually applying the page breaks to maintain the preferred structure. If you still want to enforce the page breaks, set the `auto_pagination: true` option in the Export to Word configuration. You can also use [Export to PDF](export-pdf.md), where predicting page breaks is more straightforward and works more consistently.

<a id="unsupported-plugins">

### Unsupported plugins

* [Media embed](../media-embed/media-embed.md) – Embedded media will not be included in the exported document.
* [MathType](../math-equations.md) – Supported partially. The plugin parses the data but not the formatting, losing some of the math operators and not reproducing a usable equation in the effecting file.

<a id="unsupported-features">

### Unsupported features

* Inline and block formatting [suggestions](../collaboration/track-changes/track-changes.md) – Such suggestions are not included in the exported document.
* [Comments](../collaboration/comments/comments.md) applied to whole widgets (like tables) – Such comments are not included in the exported document.

<a id="related-features">

## Related features

* The complementary [pagination feature](../pagination/pagination.md) provides live preview of the document’s page breaks, ensuring the output document looks correct.
* If you would like to export your content to a portable, universal format, using the [export to PDF](export-pdf.md) feature will allow you to generate PDF files out of your editor-created content.

<a id="common-api">

## Common API

The [`ExportWord`](../../api/module_export-word_exportword-ExportWord.md) plugin registers:

* The `'exportWord'` button.

* The `'exportWord'` command implemented by [`ExportWordCommand`](../../api/module_export-word_exportwordcommand-ExportWordCommand.md).

  You can execute the command using the [`editor.execute()`](../../api/module_core_editor_editor-Editor.md#function-execute) method. However, if you want to use the command directly (not via the toolbar button), you need to specify the [the options](../../api/module_export-word_exportword-ExportWordConfig.md) or gather them from the configuration. Otherwise, the command will not execute properly.

  The example code to use the command directly should look like this:

  ```js
  // Start generating a Word file based on the editor content and the plugin configuration.
  const config = editor.config.get( 'exportWord' );
  editor.execute( 'exportWord', config );
  ```

<a id="rest-api">

## REST API

The HTML to DOCX converter provides an API for converting HTML documents to Microsoft Word `.docx` files. Read the [REST API documentation](https://docx-converter.cke-cs.com/v2/convert/docs#section/Export-to-Word) to find out how to employ it in your implementation.

---

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