Inline-code helper

Generate the hash for script-src or style-src.

Paste the exact inline script or stylesheet. The hash is computed in the browser using SubtleCrypto, so nothing leaves the page. The output uses the same encoding as openssl dgst -sha256 -binary | openssl base64 -A.

Source

Include the source exactly as it appears inside the <script> or <style> tag — no leading or trailing whitespace unless it is part of the source.

SHA-256 is the most common; SHA-384 / SHA-512 offer no real security benefit for CSP.

The ready-to-paste directive includes the trailing quote exactly as CSP expects.

How to use the result

The hash is only valid if the source the browser receives is byte-for-byte identical.

1. Use the right tag

Inline <script> blocks go into script-src. Inline <style> blocks go into style-src.

2. Strip server-injected whitespace

HTML minifiers and servers sometimes change indentation, line endings, or add trailing newlines. If the hash fails, re-paste the source the browser actually receives and recompute.

3. Combine with nonce for trust

Hashes are great for static inline blocks you control. For dynamic content, prefer a per-request nonce via the CSP Generator.

Related reading

Conceptual background and rollout patterns.