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: 155Edge
12+Supportedsince Jul 29, 2015
Current: 154Firefox
1–16Not supported
17+Supportedsince Nov 20, 2012
Current: 157Safari
1–4Not supported
5+Supportedsince Jun 7, 2010
Current: 27MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155Firefox Android
4–16Not supported
17+Supportedsince Nov 20, 2012
Current: 157Safari iOS
1–3.2Not supported
4+Supportedsince Jun 21, 2010
Current: 27How 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
}Documentation (MDN)
Specification
Usage share
Sub-features
Support for each part of the feature (12). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| HTMLIFrameElement.sandbox | 5 | 12 | 17 | 5 | 18 | 17 | 4 |
| iframe.sandbox | 5 | 12 | 17 | 5 | 18 | 17 | 4 |
| iframe.sandbox.allow-downloads | 83 | 83 | 82 | 17 | 83 | 82 | 17 |
| iframe.sandbox.allow-forms | 5 | 79 | ≤49 | 5 | 18 | ≤49 | 4 |
| iframe.sandbox.allow-modals | 46 | 79 | 49 | 11.1 | 46 | 49 | 11.3 |
| iframe.sandbox.allow-popups | 17 | 12 | 28 | 6 | 18 | 27 | 6 |
| iframe.sandbox.allow-popups-to-escape-sandbox | 46 | 79 | 49 | 11.1 | 46 | 49 | 11.3 |
| iframe.sandbox.allow-same-origin | 5 | 79 | ≤49 | 5 | 18 | ≤49 | 4 |
| iframe.sandbox.allow-scripts | 5 | 79 | ≤49 | 5 | 18 | ≤49 | 4 |
| iframe.sandbox.allow-top-navigation | 6 | 79 | ≤49 | 5 | 18 | ≤49 | 4.2 |
| iframe.sandbox.allow-top-navigation-by-user-activation | 58 | 79 | 79 | 11.1 | 58 | 79 | 11.3 |
| iframe.sandbox.allow-top-navigation-to-custom-protocols | ✕ | ✕ | 101 | 16 | ✕ | 101 | 16 |