Remove formatting
The remove format feature lets you quickly remove any text formatting applied using inline HTML elements and CSS styles, like basic text styles (bold, italic) or font family, size, and color. This feature does not remove block-level formatting (headings, images) or semantic data (links).
# Demo
Select the content you want to clean up and press the remove format button in the toolbar.
You can use the remove format feature to easily clean up text formatting.
Here are some examples of formatting removed by this feature:
bold,
italics,
underline,
strikethrough,
code
,
subscript,
superscript,
font size, and
font family.
The remove format feature resets text alignment, too.
Note: The feature will not erase non-formatting content — your links are safe!
This demo presents a limited set of features. Visit the feature-rich editor example to see more in action.
# Installation
⚠️ New import paths
Starting with version 42.0.0, we changed the format of import paths. This guide uses the new, shorter format. Refer to the Packages in the legacy setup guide if you use an older version of CKEditor 5.
After installing the editor, add the feature to your plugin list and toolbar configuration:
import { ClassicEditor, RemoveFormat } from 'ckeditor5';
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ RemoveFormat, /* ... */ ],
toolbar: [ 'removeFormat', /* ... */ ]
} )
.then( /* ... */ )
.catch( /* ... */ );
# Configuring the remove format feature
This feature has no integration–level configuration. Once enabled, it works out–of–the–box with all core editor features.
# A short note about content types in the editor
The remove format feature is intended to help users tidy up chunks of content from unnecessary formatting. Each editor feature brings its own content types to the WYSIWYG editor. If you do not want the unnecessary formatting to be enabled in the first place, you may want to consider reducing the number of features enabled in the editor.
Doing that will spare the users the pain of manually removing formatting every time they paste content from other programs and make the editing experience smoother. The narrower set of editor features also gives you more control over the content saved to the database and prevents the accidental use of the types of content you would rather not store in your application.
# Integrating with editor features
In order for the remove formatting feature to work with custom content, you need to update the schema by setting the isFormatting
property on the custom text attribute.
This is already done for most inline elements supported by the General HTML Support plugin and its derivatives such as the Style plugin.
By default, formatting is not removed from the link elements. To remove formatting from them as well, you need to create a plugin that extends the schema and tells the editor that the linkHref
text attribute produced by the link feature is a formatting attribute:
// A simple plugin that extends the remove format feature to consider links.
function RemoveFormatLinks( editor ) {
// Extend the editor schema and mark the "linkHref" model attribute as formatting.
editor.model.schema.setAttributeProperties( 'linkHref', {
isFormatting: true
} );
}
Enable the RemoveFormatLinks
plugin in the configuration and run the editor:
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [
RemoveFormat,
RemoveFormatLinks,
// More plugins.
// ...
],
toolbar: [
'removeFormat',
// More toolbar items.
// ...
]
} )
.then( /* ... */ )
.catch( /* ... */ );
From now on, the remove format button should also remove links in the content. Learn more about attribute properties.
# Related features
CKEditor 5 has more features that can help you format your content:
- Basic text styles – The essentials, like bold, italic, and others.
- Font styles – Easily and efficiently control the font family, size, text or background color.
- Format painter – Easily copy text formatting and apply it in a different place in the edited document.
- Text alignment – Align your content left, align it right, center it, or justify.
# Common API
The RemoveFormat
plugin registers the 'removeFormat'
UI button component and a command of the same name implemented by RemoveFormatCommand
.
You can execute the command using the editor.execute()
method:
// Removes all the formatting in the selection.
editor.execute( 'removeFormat' );
We recommend using the official CKEditor 5 inspector 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.
# Contribute
The source code of the feature is available on GitHub at https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-remove-format.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.