You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/ckeditor5-link/docs/features/link.md
+45-1Lines changed: 45 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ category: features
6
6
modified_at: 2025-04-07
7
7
---
8
8
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.
10
10
11
11
## Demo
12
12
@@ -330,6 +330,34 @@ ClassicEditor
330
330
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.
331
331
</info-box>
332
332
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
+
333
361
#### Adding attributes to links using the UI (manual decorators)
334
362
335
363
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
365
393
.catch( /* ... */ );
366
394
```
367
395
396
+
#### Deprecated syntax
397
+
398
+
Older versions of CKEditor 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-boxwarning>
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
+
368
412
## Autolink feature
369
413
370
414
The {@link module:link/autolink~AutoLink `AutoLink`} feature will automatically turn URLs or email addresses into working links.
0 commit comments