Choose who can frame your page with X-Frame-Options or frame-ancestors

SettingWhat it permits
X-Frame-Options: DENYNo framing, even by another page on your own origin.
X-Frame-Options: SAMEORIGINFraming only when every ancestor page has the same origin.
Content-Security-Policy: frame-ancestors 'none'No embedding by a parent page.
Content-Security-Policy: frame-ancestors 'self'Embedding by pages on the same origin. Add specific trusted origins if other sites need to embed it.

Allow intended embeds with frame-ancestors

  • Identify which pages need to be embedded and which parent sites use them. Send a frame-ancestors policy allowing those parents on those pages; keep other pages more restrictive.

  • For nested frames, every ancestor must match. The directive reference also explains how frame-src differs: it controls the frames your page loads, not who can frame yours.

Set X-Frame-Options in the response header

Putting X-Frame-Options or frame-ancestors in a meta tag doesn't apply the framing restriction. Set the HTTP response header where your pages are served. The header reference includes server examples.

Frequently asked questions

Does X-Frame-Options replace a Content Security Policy?

No. Framing rules decide who may embed a page. They don't decide which scripts run inside it; a Content Security Policy's script rules do that.

  • Website security

    Catch leaked API keys and exposed files before someone uses them against you.

  • Security headers

    Learn which response headers guide browser behavior and where to add them.

  • Content Security Policy

    Read your content policy and investigate blocked scripts before tightening it.