# HasCrossorigin

> Provides an immutable API for the crossorigin attribute.

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

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

Used by 5 types:

- [`UIAwesome\Html\Embedded\Audio`](/docs/extensions/html/reference/embedded/audio/index.md)
- [`UIAwesome\Html\Embedded\Img`](/docs/extensions/html/reference/embedded/img/index.md)
- [`UIAwesome\Html\Embedded\Video`](/docs/extensions/html/reference/embedded/video/index.md)
- [`UIAwesome\Html\Metadata\Link`](/docs/extensions/html/reference/metadata/link/index.md)
- [`UIAwesome\Html\Metadata\Script`](/docs/extensions/html/reference/metadata/script/index.md)

Provides an immutable API for the `crossorigin` attribute.

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

## Methods

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

## Method details

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

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

Sets the `crossorigin` attribute.

Controls credentialed requests for cross-origin resources.

**Parameters**

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

**Returns**

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

**Throws**

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