# HasTarget

> Provides an immutable API for the target attribute.

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

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

Used by 3 types:

- [`UIAwesome\Html\Form\Form`](/docs/extensions/html/reference/form/form/index.md)
- [`UIAwesome\Html\Metadata\Base`](/docs/extensions/html/reference/metadata/base/index.md)
- [`UIAwesome\Html\Palpable\A`](/docs/extensions/html/reference/palpable/a/index.md)

Provides an immutable API for the `target` attribute.

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

## Methods

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

## Method details

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

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

Sets the `target` attribute.

Defines the browsing context that receives the link or form submission.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | Browsing context name, or `null` to remove the attribute. |

**Returns**

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

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): If the value is not valid.