# HasCheckedState

> Provides methods to configure the checked state of form elements like checkboxes and radio buttons.

[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) › HasCheckedState

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

Used by 2 types:

- [`UIAwesome\Html\Form\InputCheckbox`](/docs/extensions/html/reference/form/inputcheckbox/index.md)
- [`UIAwesome\Html\Form\InputRadio`](/docs/extensions/html/reference/form/inputradio/index.md)

Provides methods to configure the checked state of form elements like checkboxes and radio buttons.

## Methods

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

## Method details

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

```php
public function checked(bool|float|int|mixed[]|string|Stringable|UnitEnum|null $value): static
```

Sets the `checked` attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `bool\|float\|int\|mixed[]\|string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | Checked state. - `array`: Element is checked if the value is in the array. - `false`: Element is unchecked. - `true`: Element is checked. - `float\|int\|string\|Stringable\|UnitEnum`: Element is checked if the value matches the `value` attribute, or `on` when the element has no `value` attribute. - `null`: Attribute is removed. |

**Returns**

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