# HasContent

> Provides an immutable API for managing element content.

[API reference](/docs/api/index.md) › [HTML Mixin](/docs/extensions/html-mixin/reference/index.md) › HasContent

| trait | `UIAwesome\Html\Mixin\HasContent` |
| --- | --- |
| Source | [`src/HasContent.php`](https://github.com/ui-awesome/html-mixin/blob/main/src/HasContent.php#L14) |

Used by 2 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)

Provides an immutable API for managing element content.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-content"></span>`$content` protected | `string` | Content string assigned to the element. Default: `''`. | `HasContent` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`clearContent()`](#method-clearContent) | Clears encoded and raw content without changing other component state. | `HasContent` |
| [`content()`](#method-content) | Appends encoded content. | `HasContent` |
| [`getContent()`](#method-getContent) | Returns the content assigned to the element. | `HasContent` |
| [`html()`](#method-html) | Appends trusted raw HTML content without encoding or sanitizing it. | `HasContent` |

## Method details

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

```php
public function clearContent(): static
```

Clears encoded and raw content without changing other component state.

**Returns**

`static`: New instance with empty content.

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

```php
public function content(string|Stringable|UnitEnum ...$values): static
```

Appends encoded content.

Backed enums use their value (including `0`); pure enums use their name. Values are normalized before encoding.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `...$values` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Content to be encoded and appended. |

**Returns**

`static`: New instance with appended encoded content.

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

```php
public function getContent(): string
```

Returns the content assigned to the element.

**Returns**

`string`: Content value assigned to the element. Never `null`.

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

```php
public function html(string|Stringable|UnitEnum ...$values): static
```

Appends trusted raw HTML content without encoding or sanitizing it.

Backed enums use their value (including `0`); pure enums use their name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `...$values` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Trusted raw HTML content to be appended. |

**Returns**

`static`: New instance with appended raw HTML content.