← Back to home
Reference · Quick lookup

The iframe
cheat sheet.

Everything that matters about the <iframe> element — every attribute, every sandbox flag, every Permissions-Policy feature, every defense header you can send. One page. Paste-ready snippets at the bottom.

Updated:11 May 2026Read:8 minLevel:Reference

Every iframe attribute

AttributeValueWhat it does
srcURLURL of the document to embed. Mutually exclusive with srcdoc.
srcdocHTML stringInline HTML to render. Overrides src when both are present.
nametokenTargetable name for window.open() and form target=…
titlestringAccessible label. Required for screen-reader compliance.
sandboxtokensCapability deny-list. See the dedicated sandbox section below.
allowPermissions-PolicyFeature allowlist (camera, geolocation, payment, etc.). See section below.
allowfullscreenbooleanLets the frame call requestFullscreen(). Equivalent to allow="fullscreen".
referrerpolicypolicyReferer header sent on the request. See section below.
loadinglazy / eagerDefer off-screen frames until they near the viewport.
fetchpriorityhigh / low / autoHint to the browser about resource scheduling.
width / heightpx or %Dimensions of the rendered frame.
csppolicyExperimental — embed-only CSP enforced on the frame. Limited support.

Every sandbox flag

Space-separated tokens in the sandbox attribute. Empty value strips everything; each allow-* re-enables one capability. See the dedicated sandbox guide for caveats and recipes.

FlagRe-enables
(empty)Maximum restriction: no scripts, no forms, no popups, opaque origin.
allow-scriptsRe-enable JavaScript.
allow-same-originRestore the real origin (dangerous with allow-scripts on a same-origin frame).
allow-formsRe-enable form submission.
allow-popupsRe-enable window.open().
allow-popups-to-escape-sandboxPopups created by the frame are unsandboxed.
allow-modalsRe-enable alert / confirm / prompt / print.
allow-top-navigationRe-enable writes to window.top.location.
allow-top-navigation-by-user-activationTop-navigation, but only after a click/keypress.
allow-downloadsRe-enable download triggers.
allow-presentationRe-enable the Presentation API.
allow-pointer-lockRe-enable requestPointerLock().
allow-orientation-lockRe-enable screen.orientation.lock().
allow-storage-access-by-user-activationFrame can call requestStorageAccess() for same-site cookies.

Permissions-Policy features for the allow attribute

Space-separated or semicolon-separated list. Empty parens () = block completely; (self) = allow same-origin only; (self "https://x.example") = allow self + specific origins; * = allow everywhere.

Feature tokenWhat it controls
cameraMediaDevices.getUserMedia({ video: true })
microphoneMediaDevices.getUserMedia({ audio: true })
geolocationNavigator.geolocation API
paymentPayment Request API. Required for Apple Pay / Google Pay inside frames.
fullscreenElement.requestFullscreen()
autoplayAudio/video autoplay
encrypted-mediaEME (DRM-protected media)
clipboard-read / clipboard-writeAsync Clipboard API
publickey-credentials-getWebAuthn assertion (passkey sign-in)
usbWebUSB
serialWeb Serial API
hidWebHID
midiWeb MIDI
xr-spatial-trackingWebXR (VR/AR)
display-capturegetDisplayMedia (screen capture)
cross-origin-isolatedRequired for SharedArrayBuffer / high-resolution timers
interest-cohort / browsing-topicsFLoC and Topics API. Set to () to opt out.

referrerpolicy values

PolicyWhat gets sent in the Referer header
no-referrerNever send the Referer header.
no-referrer-when-downgradeSend full URL on same- or higher-security navigations; omit on HTTPS→HTTP.
originSend only the origin (scheme + host + port).
origin-when-cross-originFull URL same-origin, origin-only cross-origin.
same-originFull URL same-origin, nothing cross-origin.
strict-originSend origin only, never on HTTPS→HTTP.
strict-origin-when-cross-originDefault in modern browsers. Full URL same-origin, origin-only cross-origin, nothing on HTTPS→HTTP.
unsafe-urlAlways send full URL. Avoid — leaks path data cross-origin.

loading and fetchpriority

  • loading="lazy" — defer the frame until it nears the viewport. See the dedicated lazy-loading guide.
  • loading="eager" — load immediately (default).
  • fetchpriority="high" — hint to the browser this frame is critical (rarely needed for iframes).
  • fetchpriority="low" — deprioritise. Useful for tracking and analytics iframes.

Defense headers for the embedding page

Headers you send on responses you want to protect. See the dedicated clickjacking guide for context.

HeaderWhat it does
X-Frame-Options: DENYBlock any iframe from embedding this page. Legacy header, still respected.
X-Frame-Options: SAMEORIGINOnly same-origin pages may embed. Riskier than DENY because of subdomains.
Content-Security-Policy: frame-ancestors 'none'CSP-level equivalent of X-Frame-Options DENY. Supersedes XFO where supported.
Content-Security-Policy: frame-ancestors 'self' https://partner.exampleAllow specific partner origins to embed. CSP-only — XFO cannot do allowlists.
Content-Security-Policy: frame-src 'self' https://*.youtube.comLimits which origins the page itself is allowed to load iframes FROM.
Cross-Origin-Embedder-Policy: require-corpRequired (with COOP) for SharedArrayBuffer. Affects all subresources, including iframes.
Cross-Origin-Opener-Policy: same-originIsolates the browsing context group. Pairs with COEP.
Permissions-Policy: camera=()Header-level equivalent of the allow attribute. Applies to the page and all its iframes.

Snippets you will paste

Strict, no-trust embed of user HTML

<iframe sandbox srcdoc="<h1>Untrusted</h1>"></iframe>

YouTube embed with full defenses

<iframe
  src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
  title="Video title"
  loading="lazy"
  referrerpolicy="strict-origin-when-cross-origin"
  allow="autoplay; encrypted-media; picture-in-picture"
  allowfullscreen
></iframe>

Stripe payment frame

<iframe
  src="https://js.stripe.com/v3/elements-..."
  allow="payment"
  sandbox="allow-scripts allow-same-origin allow-forms allow-popups"
></iframe>

Maximum framing defense on a sensitive page

X-Frame-Options: DENY
Content-Security-Policy: frame-ancestors 'none'
Permissions-Policy: camera=(), microphone=(), geolocation=(), interest-cohort=()

List every iframe on the current page

document.querySelectorAll('iframe')

Check whether the current page is itself framed

const framed = window.self !== window.top;

Find iframes that are hidden / 1×1 pixels

Array.from(document.querySelectorAll('iframe')).filter(f =>
  f.offsetParent === null || f.offsetWidth <= 1 || f.offsetHeight <= 1
);