# CanBeAutofocus

> Provides an immutable API for the autofocus 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) › CanBeAutofocus

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

Used by 18 types:

- [`UIAwesome\Html\Core\Element\BaseBlock`](/docs/extensions/html-core/reference/element/baseblock/index.md)
- [`UIAwesome\Html\Form\AbstractInputDateTime`](/docs/extensions/html/reference/form/abstractinputdatetime/index.md)
- [`UIAwesome\Html\Form\Button`](/docs/extensions/html/reference/form/button/index.md)
- [`UIAwesome\Html\Form\InputCheckbox`](/docs/extensions/html/reference/form/inputcheckbox/index.md)
- [`UIAwesome\Html\Form\InputColor`](/docs/extensions/html/reference/form/inputcolor/index.md)
- [`UIAwesome\Html\Form\InputEmail`](/docs/extensions/html/reference/form/inputemail/index.md)
- [`UIAwesome\Html\Form\InputFile`](/docs/extensions/html/reference/form/inputfile/index.md)
- [`UIAwesome\Html\Form\InputImage`](/docs/extensions/html/reference/form/inputimage/index.md)
- [`UIAwesome\Html\Form\InputNumber`](/docs/extensions/html/reference/form/inputnumber/index.md)
- [`UIAwesome\Html\Form\InputPassword`](/docs/extensions/html/reference/form/inputpassword/index.md)
- [`UIAwesome\Html\Form\InputRadio`](/docs/extensions/html/reference/form/inputradio/index.md)
- [`UIAwesome\Html\Form\InputRange`](/docs/extensions/html/reference/form/inputrange/index.md)
- [`UIAwesome\Html\Form\InputReset`](/docs/extensions/html/reference/form/inputreset/index.md)
- [`UIAwesome\Html\Form\InputSearch`](/docs/extensions/html/reference/form/inputsearch/index.md)
- [`UIAwesome\Html\Form\InputSubmit`](/docs/extensions/html/reference/form/inputsubmit/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)

Provides an immutable API for the `autofocus` attribute.

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

## Methods

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

## Method details

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

```php
public function autofocus(bool|null $value): static
```

Sets the `autofocus` attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `bool\|null` | Whether to enable autofocus. Use `true` to enable, `false` to disable, or `null` to remove the attribute. |

**Returns**

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