Skip to main content

HTML Guide

Bad value X for attribute “integrity” on element “script”: Invalid base64-value (should be multiple of 4 bytes).

The value assigned to the integrity attribute in your script tag is not a valid base64-encoded string, which is required for Subresource Integrity (SRI).

The integrity attribute is used to ensure that the resource fetched by the browser matches the expected cryptographic hash. This value needs to be a valid base64-encoded hash, commonly generated using SHA-256, SHA-384, or SHA-512. The value format should be: [algorithm]-[base64-encoded hash]. The base64 part must have a length that is a multiple of 4, padded with = if necessary.

Example of incorrect usage:

<script
  src="https://example.com/script.js"
  integrity="sha384-BadBase64Value!"
  crossorigin="anonymous"></script>

How to fix:
Obtain the correct hash for the file and use a valid, properly padded base64 value. You can generate an SRI hash using tools such as SRI Hash Generator or the command line.

Correct usage example:

<script
  src="https://example.com/script.js"
  integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9Gh8S7f1bE0q/PuF3LtHac+obYTK2B69B1a8tT"
  crossorigin="anonymous"></script>

Always ensure the hash matches the actual file to avoid browser blocking, and that the base64 string is correctly formatted.

Learn more:

Related W3C validator issues