Skip to content

Iframe Content Blocked

Quick summary

Your iframe is blank because the target site sends X-Frame-Options or CSP headers that prevent embedding.

Why this happens

  • The target site sends X-Frame-Options: DENY or SAMEORIGIN

  • CSP frame-ancestors directive blocks embedding

  • The iframe src URL is wrong or returns a 404

  • Mixed content: HTTPS page trying to embed an HTTP iframe

Minimal example

✗ Broken code
<!-- Target site sends X-Frame-Options: DENY -->
<iframe src="https://other-site.com/page"></iframe>
<!-- Console: Refused to display in a frame -->
✓ Fixed code
<!-- If you control the target server, set: -->
<!-- X-Frame-Options: SAMEORIGIN -->
<!-- Or CSP: frame-ancestors https://your-site.com -->
<iframe src="https://your-site.com/page" sandbox="allow-same-origin"></iframe>

The target site blocks embedding via X-Frame-Options or CSP. If you control the server, adjust the headers to allow your origin. Use sandbox for security.

How to diagnose

  • Check the browser console for X-Frame-Options or CSP errors

  • Inspect the response headers of the iframe URL

  • Verify the iframe src URL is correct and accessible

How to fix

  • If you control the target server, remove or adjust X-Frame-Options and CSP headers

  • Use frame-ancestors in CSP to explicitly allow your origin

  • Fix the iframe src URL if it is wrong

  • Use https:// for the iframe src on HTTPS pages

How to prevent

  • Configure X-Frame-Options and CSP frame-ancestors intentionally

  • Test iframe embedding during development

  • Use sandbox attribute on iframes for additional security control

Related Resources

Related Glossary

Related Lessons

← Back to language