# HasMaxlength

> Provides an immutable API for the maxlength attribute.

[API reference](/docs/api/index.md) › [HTML](/docs/extensions/html/reference/index.md) › [Form](/docs/extensions/html/reference/form/index.md) › [Mixin](/docs/extensions/html/reference/form/mixin/index.md) › HasMaxlength

| trait | `UIAwesome\Html\Form\Mixin\HasMaxlength` |
| --- | --- |
| Uses traits | [`HasIntLikeAttribute`](/docs/extensions/html/reference/form/mixin/hasintlikeattribute/index.md) |
| Source | [`src/Form/Mixin/HasMaxlength.php`](https://github.com/ui-awesome/html/blob/main/src/Form/Mixin/HasMaxlength.php#L19) |

Used by 7 types:

- [`UIAwesome\Html\Form\InputEmail`](/docs/extensions/html/reference/form/inputemail/index.md)
- [`UIAwesome\Html\Form\InputPassword`](/docs/extensions/html/reference/form/inputpassword/index.md)
- [`UIAwesome\Html\Form\InputSearch`](/docs/extensions/html/reference/form/inputsearch/index.md)
- [`UIAwesome\Html\Form\InputTel`](/docs/extensions/html/reference/form/inputtel/index.md)
- [`UIAwesome\Html\Form\InputText`](/docs/extensions/html/reference/form/inputtext/index.md)
- [`UIAwesome\Html\Form\InputUrl`](/docs/extensions/html/reference/form/inputurl/index.md)
- [`UIAwesome\Html\Form\TextArea`](/docs/extensions/html/reference/form/textarea/index.md)

Provides an immutable API for the `maxlength` attribute.

See also: <https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/maxlength>.

## Methods

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

## Method details

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

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

Sets the `maxlength` attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `int\|string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | Maximum length. Must be '>= 0', or `null` to remove the attribute. |

**Returns**

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

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): if the value is not an integer-like value '>= 0'.