Subresource Integrity (SRI) Hash Generator
Drop the JavaScript and CSS files you deploy to get integrity attributes and complete tags, hash inline code for CSP, or check an existing tag.
Runs in your browser. Your files never leave your device. See how to check
…
How to do it
- 1Add files
Drop your built .js and .css files, or fetch a CDN URL that allows CORS.
- 2Choose algorithms
Select sha384 or add sha256 and sha512.
- 3Set tag options
Set the base URL, crossorigin, defer or async and the tag type per file.
- 4Copy the tags
Copy each tag, or download all tags or the JSON map.
- 5Hash inline code
Use the inline tab to get CSP hashes for inline scripts and styles.
- 6Verify
Paste existing tags, add the files and press Verify.
About this tool
When a page loads a script from a CDN, it trusts that server to deliver exactly the file the developer tested. If the CDN is compromised or a package is replaced, every visitor runs the new code. Subresource Integrity closes that gap: the integrity attribute on a script or link tag carries a cryptographic hash of the expected file, and the browser refuses to run or apply anything that does not match. The hash is a SHA-256, SHA-384 or SHA-512 digest, Base64 encoded and prefixed with the algorithm name. Getting it right needs the exact bytes of the deployed file, the matching crossorigin attribute for files on another origin, and a fresh hash after every release. This tool computes all three digests in your browser with the Web Crypto API, writes the finished tags, and checks tags you already have.
Files and tags
Drop any number of .js, .mjs and .css files. Each one gets its SHA-256, SHA-384 and SHA-512 values and a tag built from your settings: the URL, which defaults to a base path plus the file name and can be edited per file, the tag type (classic script, module script, stylesheet, preload or modulepreload), the algorithms to include, crossorigin, defer or async and an optional referrer policy. Download all tags as an HTML snippet or a JSON map of URL to integrity value for your build scripts.
Fetch a file from a URL
If a CDN sends Access-Control-Allow-Origin, as jsDelivr, unpkg and cdnjs do, you can paste the file URL and the browser fetches and hashes it directly. Servers without that header cannot be read by a web page; download the file and drop it instead.
Hashes for inline code
Content Security Policy can allow a specific inline script or style by its hash instead of using unsafe-inline. Paste the code exactly as it appears between the tags and the tool prints the source expression, such as 'sha256-...', and a ready script-src or style-src directive. Whitespace counts, so copy it unchanged.
Verify an existing tag
Paste one or more script or link tags and add the files. Files are matched to tags by name. The result follows the browser rule: only the strongest algorithm listed in the attribute is checked, and any one of its values may match. It also warns when a cross-origin tag lacks crossorigin, which makes the browser fail the load.
Limits
The hash proves the file is unchanged, not that it is safe. A file that changes on every request, such as an analytics loader without a version in its URL, cannot use SRI. SRI does not apply to images, iframes or fetch calls in this form, and the tool cannot read files from servers that block cross-origin reads.
Worked example
A team serves app.4f2c.js (182,440 bytes) and styles.9a1d.css from https://cdn.example.com/assets/. Dropping both files gives three digests each. With sha384 selected, crossorigin anonymous and defer on, the script tag reads script src set to https://cdn.example.com/assets/app.4f2c.js, integrity sha384- followed by 64 Base64 characters, crossorigin anonymous and defer. For an inline snippet document.documentElement.classList.add('js'); the CSP tab gives a sha256 source expression to add to script-src, so the policy no longer needs unsafe-inline. Pasting last month's tag with the new file shows a mismatch, a reminder that the hash must change with every build.
Quick facts
- Category: Developer & Data
- Works in your browser, no sign-up, no upload.
- Your input stays on your device.
- Available in English.
- Content last reviewed:
- Official source: W3C Subresource Integrity
Frequently asked questions
Which algorithm should I use?
sha384 is the common default and is what most CDNs publish. sha256 and sha512 are also valid. Listing several only matters during a change, because the browser checks just the strongest one listed.
Why do I need crossorigin?
For a file from another origin, the browser can only compare its bytes if it was fetched in CORS mode. Without crossorigin the integrity check fails and the file is blocked.
What happens when the hash does not match?
The browser does not run the script or apply the stylesheet and logs an error in the console. Your page behaves as if the file failed to load.
Can I use SRI for Google Fonts or analytics scripts?
Only for URLs whose content never changes. Font CSS and many tag loaders vary by browser or update in place, so a fixed hash would break them.
Is this the same as a CSP hash?
They use the same digests, but SRI protects external files and CSP hashes allow specific inline code. Both are covered here.
Are my files uploaded?
No. Hashing uses your browser's built-in Web Crypto. Only a URL you choose to fetch is requested, straight from that server.
