<p>This doesn't answer your question directly, but would simply rewriting the output in your template solve your problem? If you wanted such classes to <em>always</em> be applied then you can just do something like this in Twig:</p>
<pre><code>{{ richText|replace({
  '&lt;ul&gt;': '&lt;ul class=&quot;class1&quot;&gt;',
  '&lt;ol&gt;': '&lt;ol class=&quot;class2&quot;&gt;',
}) }}
</code></pre>

CC BY-SA 4.0
2023-09-07T16:14:36.537Z
I need to be able to add different classes to each `<ul>` element, so this wouldn't work, unfortunately.
user3092
CC BY-SA 4.0
2023-09-07T09:20:27.140Z
2023-09-07T09:20:27.140Z
Seth Warburton
<p>The CKEditor5 plugin supports custom configuration on a per-field basis, which can include style definitions. In the <a href="https://github.com/craftcms/ckeditor#configuration" rel="nofollow noreferrer">documentation</a>, you'll see how to create a custom field config. So it sounds like you might want to add a style definition like so:</p>
<pre><code>  style: {
    definitions: [
      {
        name: 'Class One',
        element: 'ul',
        classes: ['class-1']
      },
      {
        name: 'Class Two',
        element: 'ul',
        classes: ['class-2']
      },
    ]
  }

</code></pre>
<p>Once these are registered, they should show up in the &quot;styles&quot; dropdown, and be applicable when the matching tag is selected. You can also the CSS for these styles in the Custom Styles field, which controls how they are displayed in the editor.</p>
<p>Once these styles are registered, CKEditor shouldn't filter them out on save. The HTMLPurifier config is helpful in this case as well.</p>

CC BY-SA 4.0
2023-09-12T23:02:43.223Z
2023-09-12T23:02:43.223Z
Dalton Rooney
<p>CKEditor5 filters out any classes applied to HTML elements. However, I'd like to allow certain classes to be applied to <code>&lt;ul&gt;</code> elements (e.g. <code>class1</code>, <code>class2</code>) without CKEditor5 stripping them out.</p>
<p>I tried creating an HTML Purifier config (as below), but the classes I apply in Source still gets stripped out upon save.</p>
<pre><code>{
   &quot;HTML.Allowed&quot;: &quot;ol[class],li&quot;
}
</code></pre>

<ckeditor5>
Prevent CKEditor5 from filtering out classes
# Prevent CKEditor5 from filtering out classes

(Asked by: username_0 on 2023-09-06)

CKEditor5 filters out any classes applied to HTML elements. However, I'd like to allow certain classes to be applied to  elements (e.g. class1, class2) without CKEditor5 stripping them out.
I tried creating an HTML Purifier config (as below), but the classes I apply in Source still gets stripped out upon save.
{
   "HTML.Allowed": "ol[class],li"
}

**Tags:** ckeditor5


---

## 2 answers

### Answer by username_1 on 2023-09-07. Score: 1

This doesn't answer your question directly, but would simply rewriting the output in your template solve your problem? If you wanted such classes to always be applied then you can just do something like this in Twig:
{{ richText|replace({
  '': '',
  '': '',
}) }}

> **Comments:**
> **username_0**: I need to be able to add different classes to each `<ul>` element, so this wouldn't work, unfortunately.  

---

### Answer by username_2 on 2023-09-12. Score: 0

The CKEditor5 plugin supports custom configuration on a per-field basis, which can include style definitions. In the documentation, you'll see how to create a custom field config. So it sounds like you might want to add a style definition like so:
  style: {
    definitions: [
      {
        name: 'Class One',
        element: 'ul',
        classes: ['class-1']
      },
      {
        name: 'Class Two',
        element: 'ul',
        classes: ['class-2']
      },
    ]
  }


Once these are registered, they should show up in the "styles" dropdown, and be applicable when the matching tag is selected. You can also the CSS for these styles in the Custom Styles field, which controls how they are displayed in the editor.
Once these styles are registered, CKEditor shouldn't filter them out on save. The HTMLPurifier config is helpful in this case as well.


---

