Skip to main content

Batoi navigation

Retain Inline Class and Tags in CKEditor

CKEditor is a rich text editor which enables writing content directly inside of web pages or online applications. Its core code is written in JavaScript and it is developed by CKSource.

LinkedIn X Facebook

Retain Inline Class and Tags in CKEditor

CKEditor automatically strips the style classes when toggled between source view and HTML view.

For example create a div in CKEditor.

image-1

CKEditor strips the class from the , so when you hit source again it will change to

image-2

This behavior is caused by the 'Advanced Content Filter' present in the CKEditor. This behavior can be turned off in the config.js.

The easiest method is to add the following code in config.js.

CODE

  1. config.allowedContent = true;

The code mentioned above removes the filtering. However, it works only for attributes with 'id'. For attributes with style and classes, you should add different code. To allow style, class and other attributes in CKEditor, add the following codes to config.js along with the code mentioned above.

Allow any class and style in CKEditor.

  1. config.extraAllowedContent = '*(*)';

Allow only class=”newclass”.

  1. config.extraAllowedContent = '*(newclass)';

Allow class="newclass" only for p tag.

  1. config.extraAllowedContent = 'p(newclass)';

Allow 'id' attribute only.

  1. config.extraAllowedContent = '*[id]';

Allow style tag ().

  1. config.extraAllowedContent = 'style';

Allow for all attributes.

  1. config.extraAllowedContent = '*[id];*(*);*{*};p(*)[*]{*};div(*)[*]{*};li(*)[*]{*};ul(*) [*]{*};span(*)[*]{*};table(*)[*]{*};td(*)[*]{*}';

Remember to clean the browser's cache to see it work. The codes above will completely disable the content filtering in CKEditor.

Back to Developers Blog Back to top

Continue reading recent articles in this category.

Modern URL Infrastructure with DYN Microservicelets

A consistent path structure across public pages, private deployments, and SaaS workspaces

Read article

The Need for NoSQL Databases: An Everyday Guide

NoSQL databases are designed to store and manage data differently from relational databases. They do not necessarily use the traditional table-based structure and often do not use SQL as a query language.

Read article

Understanding DMARC and Its Practical Implementation

Protect your domain from email spoofing and phishing attacks with our comprehensive guide to DMARC. Learn the fundamentals, importance, and step-by-step implementation to enhance your email security and brand reputation.

Read article

Explore further with Batoi

Browse practical resources, discover other blog categories, or receive updates by email.

Resources All blog categories Subscribe to updates