# SiAvatarBackgroundColorDirective documentation

**Kind:** directive

**Selector:** `[siAvatarBackgroundColor]`

```
import { SiAvatarBackgroundColorDirective } from '@siemens/element-ng/avatar';
```

The directive provide a CSS variable --background with a color based on the initials or alt text.

```
directive SiAvatarBackgroundColorDirective implements OnChanges
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [autoColor](<https://github.com/siemens/element/blob/main/projects/element-ng/avatar/si-avatar-background-color.directive.ts#L44-L44>) | `boolean` | `false` | Automatically calculates the background color. If set, [color](<index.html#SiAvatarBackgroundColorDirective.color>) will be ignored. |
| [color](<https://github.com/siemens/element/blob/main/projects/element-ng/avatar/si-avatar-background-color.directive.ts#L36-L36>) | `number` | `undefined` | The desired color index from $si-sys-color-data-categorical-\* color tokens. This can be set to any kind of positive integer that is then mapped to a color index. A better way to set a pseudo-random color is to set [autoColor](<index.html#SiAvatarBackgroundColorDirective.autoColor>) to `true`. |

#### Attributes and Methods

##### calculateColorFromInitials

[Source for calculateColorFromInitials](<https://github.com/siemens/element/blob/main/projects/element-ng/avatar/si-avatar-background-color.directive.ts#L59-L70>)

Update background color variable based on the initials or placeholder text.

```
calculateColorFromInitials(displayInitials?: string): void
```

#### Parameters

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [displayInitials](<https://github.com/siemens/element/blob/main/projects/element-ng/avatar/si-avatar-background-color.directive.ts#L59-L59>) (optional) | `string` |  |  |

**Returns:** [void](<https://www.typescriptlang.org/docs/handbook/2/functions.html#void>)
