# AttributesInterface

> Defines the public contract for objects that manage HTML attributes.

[API reference](/docs/api/index.md) › [HTML Contracts](/docs/extensions/html-contracts/reference/index.md) › [Attribute](/docs/extensions/html-contracts/reference/attribute/index.md) › AttributesInterface

| interface | `UIAwesome\Html\Contracts\Attribute\AttributesInterface` |
| --- | --- |
| Source | [`src/Attribute/AttributesInterface.php`](https://github.com/ui-awesome/html-contracts/blob/main/src/Attribute/AttributesInterface.php#L15) |

Implemented by 4 types:

- [`UIAwesome\Html\Core\Element\BaseBlock`](/docs/extensions/html-core/reference/element/baseblock/index.md)
- [`UIAwesome\Html\Core\Element\BaseInline`](/docs/extensions/html-core/reference/element/baseinline/index.md)
- [`UIAwesome\Html\Core\Element\BaseVoid`](/docs/extensions/html-core/reference/element/basevoid/index.md)
- [`UIAwesome\Html\Contracts\Form\FormControlInterface`](/docs/extensions/html-contracts/reference/form/formcontrolinterface/index.md)

Defines the public contract for objects that manage HTML attributes.

Provides an immutable API for adding, updating, reading, and removing HTML attributes on elements.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`addAttribute()`](#method-addAttribute) abstract | Adds or updates a single HTML attribute for the element. | `AttributesInterface` |
| [`attributes()`](#method-attributes) abstract | Adds or updates the supplied HTML attributes, preserving all other attributes. | `AttributesInterface` |
| [`class()`](#method-class) abstract | Sets the `class` attribute. | `AttributesInterface` |
| [`getAttribute()`](#method-getAttribute) abstract | Returns the value of a single HTML attribute. | `AttributesInterface` |
| [`getAttributes()`](#method-getAttributes) abstract | Returns the array of HTML attributes for the element. | `AttributesInterface` |
| [`removeAttribute()`](#method-removeAttribute) abstract | Removes a specific HTML attribute from the element. | `AttributesInterface` |

## Method details

### addAttribute() <span id="method-addAttribute"></span>

```php
abstract public function addAttribute(string|UnitEnum $key, mixed $value): static
```

Adds or updates a single HTML attribute for the element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Attribute name. |
| `$value` | `mixed` | Attribute value. Use `null` to remove the attribute. |

**Returns**

`static`: New instance with the updated attribute.

### attributes() <span id="method-attributes"></span>

```php
abstract public function attributes(mixed[] $values): static
```

Adds or updates the supplied HTML attributes, preserving all other attributes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$values` | `mixed[]` | Associative array of attribute keys and values. |

**Returns**

`static`: New instance with the updated attributes.

### class() <span id="method-class"></span>

```php
abstract public function class(string|Stringable|UnitEnum|null $value, bool $override = false): static
```

Sets the `class` attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | CSS class value, or `null` to remove the attribute. |
| `$override` | `bool` | Whether to override existing classes (`true`) or merge (`false`). |

**Returns**

`static`: New instance with the updated `class` attribute.

### getAttribute() <span id="method-getAttribute"></span>

```php
abstract public function getAttribute(string|UnitEnum $key, mixed $default = null): mixed
```

Returns the value of a single HTML attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Attribute name. |
| `$default` | `mixed` | Default value when the attribute is missing. |

**Returns**

`mixed`: Attribute value or default.

### getAttributes() <span id="method-getAttributes"></span>

```php
abstract public function getAttributes(): mixed[]
```

Returns the array of HTML attributes for the element.

**Returns**

`mixed[]`: Attributes array assigned to the element.

### removeAttribute() <span id="method-removeAttribute"></span>

```php
abstract public function removeAttribute(string|UnitEnum $key): static
```

Removes a specific HTML attribute from the element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Attribute name to remove. |

**Returns**

`static`: New instance without the specified attribute.