# HasClass

> Provides an immutable API for the class attribute.

[API reference](/docs/api/index.md) › [HTML Attribute](/docs/extensions/html-attribute/reference/index.md) › [Global](/docs/extensions/html-attribute/reference/global/index.md) › HasClass

| trait | `UIAwesome\Html\Attribute\Global\HasClass` |
| --- | --- |
| Source | [`src/Global/HasClass.php`](https://github.com/ui-awesome/html-attribute/blob/main/src/Global/HasClass.php#L17) |

Used 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\BaseInput`](/docs/extensions/html-core/reference/element/baseinput/index.md)
- [`UIAwesome\Html\Core\Element\BaseVoid`](/docs/extensions/html-core/reference/element/basevoid/index.md)

Provides an immutable API for the `class` attribute.

See also: <https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class>.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`class()`](#method-class) | Sets the `class` attribute. | `HasClass` |

## Method details

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

```php
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.