Font Awesome icons vanish and the console shows CSP violations
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'".Short answer
Font Awesome's own troubleshooting page says Kits are not compatible with Content Security Policy. If your site sends a strict policy, switch to the self-hosted or npm setup, turn off automatic CSS insertion, and link the stylesheet yourself. That keeps the policy intact without opening it to extra hosts.
Fix it fast
1Find out which cause you have
Open the console, note which directive each violation names, and print the policy the server sends. Then check how Font Awesome is loaded: a Kit script, a self-hosted file or an npm package.
curl -sI https://example.com/ | grep -i "content-security-policy" curl -s https://example.com/ | grep -iE "kit.fontawesome|fontawesome"2Match what you see, then jump to its fix
- 1
The page loads a script from kit.fontawesome.com and the icons fail only when the policy is on.A Kit is used on a site that sends a CSPFix - 2
A style-src violation appears although the script file loads.Self-hosted JavaScript inserts its CSS into the pageFix - 3
A React, Vue or bundled app shows the same style-src violation.The npm svg-core package inserts its CSS at runtimeFix
- 1
What does the error look like?
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'".Refused to load the script 'https://kit.fontawesome.com/your-kit-id.js' because it violates the following Content Security Policy directive: "script-src 'self'".
Cause 1 of 3
A Kit is used on a site that sends a CSP
1Check
The Font Awesome troubleshooting page says that if a Kit is not working you should make sure you are not using Subresource Integrity or Content Security Policy, because these features are not compatible with Kits.
curl -s https://example.com/ | grep -o "https://kit.fontawesome.com/[^\"]*"2Fix
Stop using the Kit script on that site. Self-host the files, or install the npm package, and follow the settings in the next cause.
<!-- remove -->
<script src="https://kit.fontawesome.com/your-kit-id.js"></script>3Verify
Reload with the policy on. No request to kit.fontawesome.com should remain.
curl -s https://example.com/ | grep -c "kit.fontawesome.com"Confirmed by docs.fontawesome.com
Cause 2 of 3
Self-hosted JavaScript inserts its CSS into the page
1Check
The Font Awesome security page says the default setup will violate a strict CSP because the library tries to insert CSS into the document head.
curl -sI https://example.com/ | grep -i "content-security-policy" | tr ';' '\n' | grep -i "style-src"2Fix
For the self-hosted all.js, set data-auto-add-css to false on the script tag, and link the CSS file yourself.
<script src="/fontawesome/js/all.js" data-auto-add-css="false"></script>
<link href="/fontawesome/css/svg-with-js.css" rel="stylesheet" />3Verify
Reload. The style-src violation should be gone and the icons should render.
curl -sI https://example.com/fontawesome/css/svg-with-js.css | head -n 1Confirmed by docs.fontawesome.com
Cause 3 of 3
The npm svg-core package inserts its CSS at runtime
1Check
The same security page documents the autoAddCss setting for the fontawesome-svg-core package, and notes the CSS file lives at node_modules/@fortawesome/fontawesome-svg-core/styles.css.
grep -rn "fontawesome-svg-core" package.json2Fix
Set config.autoAddCss to false before any other Font Awesome call, and import the stylesheet as a normal file.
import { config } from '@fortawesome/fontawesome-svg-core'
import '@fortawesome/fontawesome-svg-core/styles.css'
config.autoAddCss = false3Verify
Rebuild, reload with the policy on, and check that the console has no new violation.
npm run buildConfirmed by docs.fontawesome.com
How do I stop it coming back?
- Decide at the start whether the site needs a CSP; if it does, do not use a Kit.
- Self-host icons or use the npm package, and load their CSS as a file.
- Test policy changes in Content-Security-Policy-Report-Only before they are enforced.
- Pin the Font Awesome version you self-host, so a file path does not change under you.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Security
The browser refuses to load a font because of your Content Security Policy
Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.
A font is blocked when the font-src directive, or default-src when font-src is missing, does not allow where the font comes from.
3 causes, each with a fixWeb apps
A Chrome extension built with webpack is blocked for using eval
Insecure CSP value "'unsafe-eval'" in directive 'script-src'.
Extension pages cannot evaluate strings as code, and Manifest V3 does not let you add unsafe-eval.
3 causes, each with a fixWeb apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fix