# Undo/Redo

The undo feature lets you withdraw recent changes to your content as well as bring them back. You can also selectively revert past changes, not just the latest ones.

<a id="demo">

## Demo

Use the demo below to try out the undo and redo mechanism. Play around with the content. Try introducing some changes and then use the toolbar buttons to undo or redo them.

Alternatively, use the well-known keyboard shortcut `Ctrl` + `Z` (this would be `Cmd` + `Z` on Mac) for undo. For redo, you can use either `Ctrl` + `Y` or `Ctrl` + `Shift` + `Z` (respectively with `Cmd` on Mac).

<!-- 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="additional-feature-information">

## Additional feature information

All operations of the undo feature are remembered and organized into batches that can later be easily undone or redone. Thanks to this approach, the feature can selectively revert past changes, not just the latest ones. This allows handling asynchronous actions such as image uploads without blocking the user from editing the document in the meantime.

The selective undo is heavily used in [real-time collaboration](collaboration/real-time-collaboration/real-time-collaboration.md) environments. In such a scenario, a specific user should only be able to revert their changes, while keeping the changes made by other users intact (unless there is an editing conflict). By omitting some changes and going down the stack, it is possible to only revert selected changes.

The feature supports both toolbar buttons and [keyboard shortcuts](accessibility.md#keyboard-shortcuts) for convenient and easy operation.

<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, Undo } from 'ckeditor5';

ClassicEditor
	.create( {
		licenseKey: '<YOUR_LICENSE_KEY>', // Or 'GPL'.
		plugins: [ Undo, /* ... */ ],
		toolbar: [ 'undo', 'redo', /* ... */ ],
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
```

**CDN**

```js
const { ClassicEditor, Undo } = CKEDITOR;

ClassicEditor
	.create( {
		licenseKey: '<YOUR_LICENSE_KEY>',
		plugins: [ Undo, /* ... */ ],
		toolbar: [ 'undo', 'redo', /* ... */ ],
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
```

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

<a id="common-api">

## Common API

The [Undo](../api/module_undo_undo-Undo.md) plugin is a “glue” plugin that loads the [`UndoEditing`](../api/module_undo_undoediting-UndoEditing.md) engine and the [`UndoUI`](../api/module_undo_undoui-UndoUI.md) features.

The `UndoEditing` feature registers the following commands:

* The [`UndoCommand`](../api/module_undo_undocommand-UndoCommand.md) which can be programmatically called as `undo` and is used to retrieve editor history from a batch.

  ```js
  editor.execute( 'undo');
  ```

  You can use it to retrieve changes from the latest batch, or from some previous batch (for example, changes made by a selected user in a collaborative environment):

  ```js
  editor.execute( 'undo', batchToUndo );
  ```

* The [`RedoCommand`](../api/module_undo_redocommand-RedoCommand.md) is used to restore undo state from batch and is called as `redo`.

  ```js
  editor.execute( 'redo');
  ```

The [`UndoUI`](../api/module_undo_undoui-UndoUI.md) feature introduces the `undo` and `redo` buttons to the editor toolbar.

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

<a id="contribute">

## Contribute

The source code of the feature is available on GitHub at <https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-undo>.

---

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