Skip to content

Commit d666499

Browse files
authored
Docs: updating classes and styles.
Docs: updating classes and styles for links.
2 parents e003cc8 + aafa0b6 commit d666499

File tree

1 file changed

+45
-1
lines changed
  • packages/ckeditor5-link/docs/features

1 file changed

+45
-1
lines changed

packages/ckeditor5-link/docs/features/link.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ category: features
66
modified_at: 2025-04-07
77
---
88

9-
The link feature lets you insert hyperlinks into your content and provides a UI to create and edit them. Thanks to the [autolink](#autolink-feature) plugin, typed or pasted URLs and email addresses automatically become working links.
9+
The link feature lets you insert hyperlinks into your content and provides a UI to create and edit them. Thanks to the [autolink](#autolink-feature) plugin, typed or pasted URLs and email addresses are automatically converted into working links.
1010

1111
## Demo
1212

@@ -330,6 +330,34 @@ ClassicEditor
330330
If you want add the `target` and `rel` attributes to all external links in your content, we prepared a [dedicated configuration](#adding-target-and-rel-attributes-to-external-links) for that purpose. Thanks to this, you do not have to define the automatic decorator by yourself.
331331
</info-box>
332332

333+
#### Adding classes and styles to links
334+
335+
In addition to adding custom HTML attributes, link decorators can also apply CSS classes and inline styles to a link. It works for both **automatic** decorators (based on rules) and **manual** decorators (toggled in the UI). You must provide classes and styles through the dedicated `classes` and `styles` properties in the decorator configuration.
336+
337+
Manual decorators add a toggle to the link UI, allowing the user to enable or disable additional link features. The decorator properties are applied to the link element whenever the toggle is enabled.
338+
339+
``` js
340+
ClassicEditor
341+
.create( document.querySelector( '#editor' ), {
342+
link: {
343+
decorators: {
344+
highlighted: {
345+
mode: 'manual',
346+
label: 'Highlighted link',
347+
defaultValue: false,
348+
classes: 'link-highlighted',
349+
styles: {
350+
background: 'yellow',
351+
'font-weight': 'bold'
352+
}
353+
}
354+
}
355+
}
356+
} );
357+
```
358+
359+
When you enable the "Highlighted link" toggle, the editor output adds the class and styles to the link element.
360+
333361
#### Adding attributes to links using the UI (manual decorators)
334362

335363
Manual link decorators are represented in the link editing balloon as switch buttons. The users can use them to control the presence of attributes of a particular link (check out the [demo](#demo) to learn more). Each manual decorator {@link module:link/linkconfig~LinkDecoratorManualDefinition definition} has a human-readable label displayed next to the switch button in the link editing balloon. Make sure it is compact and precise for the convenience of the users.
@@ -365,6 +393,22 @@ ClassicEditor
365393
.catch( /* ... */ );
366394
```
367395

396+
#### Deprecated syntax
397+
398+
Older versions of CKEditor&nbsp;5 allowed classes and styles inside the `attributes` field:
399+
400+
``` js
401+
// ❌ Deprecated – do not use:
402+
attributes: {
403+
class: 'my-class',
404+
style: 'color: red'
405+
}
406+
```
407+
408+
<info-box warning>
409+
This syntax remains compatible for backward purposes but is deprecated and triggers a console warning. Use the `classes` and `styles` properties instead.
410+
</info-box>
411+
368412
## Autolink feature
369413

370414
The {@link module:link/autolink~AutoLink `AutoLink`} feature will automatically turn URLs or email addresses into working links.

0 commit comments

Comments
 (0)