# HasMedia

> Provides an immutable API for the media attribute.

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

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

Used by 4 types:

- [`UIAwesome\Html\Embedded\Source`](/docs/extensions/html/reference/embedded/source/index.md)
- [`UIAwesome\Html\Metadata\Link`](/docs/extensions/html/reference/metadata/link/index.md)
- [`UIAwesome\Html\Metadata\Meta`](/docs/extensions/html/reference/metadata/meta/index.md)
- [`UIAwesome\Html\Metadata\Style`](/docs/extensions/html/reference/metadata/style/index.md)

Provides an immutable API for the `media` attribute.

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

## Methods

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

## Method details

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

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

Sets the `media` attribute.

Specifies the media query for the linked resource.

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

**Returns**

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