# LinkDecoratorAutomaticDefinition

interface

Describes an automatic [link decorator](module_link_linkconfig-LinkConfig.md#member-decorators). This decorator type matches all links in the editor content against a function that decides whether the link should receive a pre–defined set of attributes.

It takes an object with key-value pairs of attributes and a callback function that must return a Boolean value based on the link's `href` (URL). When the callback returns `true`, attributes are applied to the link.

For example, to add the `target="_blank"` attribute to all links in the editor starting with `http://`, the configuration could look like this:

```typescript
{
	mode: 'automatic',
	callback: url => url.startsWith( 'http://' ),
	attributes: {
		target: '_blank'
	}
}
```

**Note**: If there is a conflict between the active manual decorator and automatic decorator (e.g. both try to manage the same attribute), the manual decorator takes precedence and the automatic one is ignored. It's also highly discouraged to have multiple automatic decorators managing the same attribute.

**Note**: Since the `target` attribute management for external links is a common use case, there is a predefined automatic decorator dedicated for that purpose that can be enabled by turning a single option on. Check out the [`config.link.addTargetToExternalLinks`](module_link_linkconfig-LinkConfig.md#member-addTargetToExternalLinks) configuration description to learn more.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-link/src/linkconfig.ts#L258)

<a id="properties">

## Properties

<a id="member-attributes">

### `attributes?: Record<string, string>`

Key-value pairs used as link attributes added to the output during the [downcasting](../framework/architecture/editing-engine.md#conversion). Attributes should follow the [`ViewElementDefinition`](module_engine_view_elementdefinition-ViewElementDefinition.md) syntax.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-link/src/linkconfig.ts#L275)

<a id="member-callback">

### `callback: ( url: string | null ) => boolean`

Takes a `url` as a parameter and returns `true` if the `attributes` should be applied to the link.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-link/src/linkconfig.ts#L268)

<a id="member-classes">

### `classes?: ArrayOrItem<string>`

Class names used as link classes added to the output during the [downcasting](../framework/architecture/editing-engine.md#conversion). Classes should follow the [`ViewElementDefinition`](module_engine_view_elementdefinition-ViewElementDefinition.md) syntax.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-link/src/linkconfig.ts#L289)

<a id="member-mode">

### `mode: 'automatic'`

Link decorator type. It is `'automatic'` for all automatic decorators.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-link/src/linkconfig.ts#L263)

<a id="member-styles">

### `styles?: Record<string, string>`

Key-value pairs used as link styles added to the output during the [downcasting](../framework/architecture/editing-engine.md#conversion). Styles should follow the [`ViewElementDefinition`](module_engine_view_elementdefinition-ViewElementDefinition.md) syntax.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-link/src/linkconfig.ts#L282)

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
