coderef

Sandboxed iframesBaseline · Widely available

The sandbox attribute for the <iframe> HTML element sets many security restrictions on the iframe, such as preventing form submissions or opening modal dialogs. Optional allow- values relax specific restrictions.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jul 29, 2015. Widely available since Jan 29, 2018.

Browser support

DesktopChrome
1–4Not supported
5+Supportedsince May 25, 2010
Current: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1–16Not supported
17+Supportedsince Nov 20, 2012
Current: 157
Safari
1–4Not supported
5+Supportedsince Jun 7, 2010
Current: 27
MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155
Firefox Android
4–16Not supported
17+Supportedsince Nov 20, 2012
Current: 157
Safari iOS
1–3.2Not supported
4+Supportedsince Jun 21, 2010
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: sandbox.

Feature detection

JS · check before using
if ("sandbox" in document.createElement("iframe")) {
  // the sandbox attribute/property of <iframe> is supported
}

Sub-features

Support for each part of the feature (12). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
HTMLIFrameElement.sandbox51217518174
iframe.sandbox51217518174
iframe.sandbox.allow-downloads83838217838217
iframe.sandbox.allow-forms579≤49518≤494
iframe.sandbox.allow-modals46794911.1464911.3
iframe.sandbox.allow-popups171228618276
iframe.sandbox.allow-popups-to-escape-sandbox46794911.1464911.3
iframe.sandbox.allow-same-origin579≤49518≤494
iframe.sandbox.allow-scripts579≤49518≤494
iframe.sandbox.allow-top-navigation679≤49518≤494.2
iframe.sandbox.allow-top-navigation-by-user-activation58797911.1587911.3
iframe.sandbox.allow-top-navigation-to-custom-protocols✕✕10116✕10116