# HasName

> Provides an immutable API for the name attribute.

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

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

Used by 10 types:

- [`UIAwesome\Html\Core\Element\BaseInput`](/docs/extensions/html-core/reference/element/baseinput/index.md)
- [`UIAwesome\Html\Form\AbstractChoiceList`](/docs/extensions/html/reference/form/abstractchoicelist/index.md)
- [`UIAwesome\Html\Form\Button`](/docs/extensions/html/reference/form/button/index.md)
- [`UIAwesome\Html\Form\Fieldset`](/docs/extensions/html/reference/form/fieldset/index.md)
- [`UIAwesome\Html\Form\Form`](/docs/extensions/html/reference/form/form/index.md)
- [`UIAwesome\Html\Form\Output`](/docs/extensions/html/reference/form/output/index.md)
- [`UIAwesome\Html\Form\Select`](/docs/extensions/html/reference/form/select/index.md)
- [`UIAwesome\Html\Form\TextArea`](/docs/extensions/html/reference/form/textarea/index.md)
- [`UIAwesome\Html\Interactive\Details`](/docs/extensions/html/reference/interactive/details/index.md)
- [`UIAwesome\Html\Metadata\Meta`](/docs/extensions/html/reference/metadata/meta/index.md)

Provides an immutable API for the `name` attribute.

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

## Methods

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

## Method details

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

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

Sets the `name` attribute.

Defines the metadata name or form control name.

**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` | Name value, or `null` to remove the attribute. |

**Returns**

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