# CanBeSelected

> Provides an immutable API for the selected attribute.

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

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

Used by 1 type:

- [`UIAwesome\Html\Form\Option`](/docs/extensions/html/reference/form/option/index.md)

Provides an immutable API for the `selected` attribute.

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

## Methods

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

## Method details

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

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

Sets the `selected` attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `bool\|null` | Selected state. Use `true` to mark selected, `false` to unselect, or `null` to remove the attribute. |

**Returns**

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