# HasAs

> Provides an immutable API for the as attribute.

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

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

Used by 1 type:

- [`UIAwesome\Html\Metadata\Link`](/docs/extensions/html/reference/metadata/link/index.md)

Provides an immutable API for the `as` attribute.

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

## Methods

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

## Method details

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

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

Sets the `as` attribute.

Identifies the resource type for preload and modulepreload links.

**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` | Resource type token, or `null` to remove the attribute. |

**Returns**

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

**Throws**

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