# HasNonce

> Provides an immutable API for the nonce attribute.

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

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

Used by 1 type:

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

Provides an immutable API for the `nonce` attribute.

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

## Methods

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

## Method details

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

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

Sets the `nonce` attribute.

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

**Returns**

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