# HasCharset

> Provides an immutable API for the charset attribute.

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

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

Used by 1 type:

- [`UIAwesome\Html\Metadata\Meta`](/docs/extensions/html/reference/metadata/meta/index.md)

Provides an immutable API for the `charset` attribute.

See also: <https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta#charset>.

## Methods

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

## Method details

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

```php
public function charset(string|Stringable|UnitEnum|null $value): static
```

Sets the `charset` attribute.

Declares the document character encoding.

**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` | Character encoding token, or `null` to remove the attribute. |

**Returns**

`static`: New instance with the updated `charset` attribute. [`Charset`](/docs/extensions/html-attribute/reference/values/charset/index.md) for predefined enum values.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): If the value is not valid.