`nonce` HTML global attribute
The nonce global attribute is a content attribute defining a cryptographic nonce ("number used once") which can be used by Content Security Policy to determine whether or not a given fetch will
The nonce global attribute
is a content attribute defining a cryptographic nonce ("number used once") which can be used by
Content Security Policy to determine whether or not a given fetch will
be allowed to proceed for a given element.
Description
The nonce attribute is useful to allowlist specific elements, such as a particular inline script or style elements.
It can help you to avoid using the CSP unsafe-inline directive, which would allowlist all inline scripts or styles.
[!NOTE] Only use
noncefor cases where you have no way around using unsafe inline script or style contents. If you don't neednonce, don't use it. If your script is static, you could also use a CSP hash instead. (See usage notes on unsafe inline script.) Always try to take full advantage of CSP protections and avoid nonces or unsafe inline scripts whenever possible.