On an HTML <iframe>, what does the allow attribute control, and how is it different from the sandbox attribute?
answer
- two attributes, two different axes
- feature delegation, not capability stripping
- semicolon-separated, quoted allowlist keywords
- cannot grant what the page lacks
- the old boolean fullscreen shorthand
basics
~20 sThe allow attribute delegates powerful features such as camera, microphone, geolocation, fullscreen and payment to an embedded frame, which otherwise gets none of them cross-origin. sandbox is a separate attribute that strips generic document capabilities like scripting, forms and navigation.
solid answer
~40 sThey are two independent attributes solving two different problems. `sandbox` removes ordinary document capabilities — script execution, form submission, popups, top-level navigation, the frame's real origin. `allow` is about **feature delegation**: a cross-origin frame is denied powerful device and API features by default, and `allow` hands specific ones down, as in `allow="camera; microphone; fullscreen"`. Each entry may carry an allowlist — `allow="geolocation 'self'"`, `'src'`, `'none'`, `*`, or explicit origins — and delegation can never grant a frame more than the embedding page itself holds. The legacy `allowfullscreen` attribute is the old shorthand for `allow="fullscreen"`. You commonly need both attributes on one element: a video embed might carry `sandbox="allow-scripts"` to contain it and `allow="fullscreen; picture-in-picture"` to let the feature it actually needs through.
go deeper
Know that <iframe> has two different restricting attributes: sandbox for baseline document capabilities and allow for powerful features like camera, microphone and fullscreen. Do not use one name for the other.
Explain the delegation model and the syntax: semicolon-separated feature entries with optional 'self' / 'src' / 'none' / * allowlists, cross-origin frames denied by default, and allowfullscreen as the legacy shorthand for allow="fullscreen".
Demonstrate reading a real embed element as several independent decisions and granting the narrowest allowlist that works — scoping to 'src' so a navigation drops the grant, and knowing that delegation never bypasses the user's own permission decision.
Own the standard for third-party embeds across a product: which features any vendor embed is permitted to request, how that list gets reviewed when a vendor's embed code changes, and how those defaults are enforced rather than left to whoever pastes the snippet.
## Two attributes, two axes Candidates routinely fuse `sandbox` and `allow` into one mental slot labelled "the iframe security attributes". They restrict different things and neither substitutes for the other. - **`sandbox`** operates on the *document's* baseline capabilities: may it run script, submit forms, open popups, navigate the top-level tab, download files, keep its real origin. It is deny-first — the attribute strips, tokens grant back. - **`allow`** operates on *powerful features* the browser gates behind permission: camera, microphone, geolocation, fullscreen, autoplay, payment, display capture, picture-in-picture, encrypted media. For a cross-origin frame these default to denied, and `allow` is how the embedder passes one down. A frame can be fully unsandboxed and still be unable to reach the camera, and a heavily sandboxed frame can still be granted fullscreen. The axes are orthogonal. ## Syntax The value is a semicolon-separated list of feature entries, each optionally followed by an allowlist: ```html <iframe src="https://meet.example/room/42" allow="camera; microphone; fullscreen; display-capture 'src'" title="Video call"></iframe> ``` The allowlist values you will see are: - `*` — any origin the frame navigates to. - `'self'` — the embedding page's own origin. - `'src'` — the origin of the frame's `src`, which is the sensible default for a third-party embed that might navigate. - `'none'` — nobody. - Explicit origins, e.g. `https://widget.example`. Writing a bare feature name (`allow="camera"`) uses the default allowlist for that entry, which is `'src'` in the attribute context. Note the quoting convention: `'self'`, `'src'` and `'none'` are written with literal single quotes inside the attribute value — a detail people get wrong when hand-writing it. ## Delegation never manufactures permission Two things a good answer states explicitly. First, `allow` **delegates**, it does not grant: if the embedding page itself does not have the feature — because the user denied it, or because the page's own environment withholds it — nothing passes down. Second, delegation is not the same as consent: the browser may still prompt the user before the frame actually gets the camera. `allow` removes the structural block, not the human decision. ## The legacy shorthands `allowfullscreen` on `<iframe>` is a boolean attribute predating the general mechanism, and it is defined as the equivalent of `allow="fullscreen"`. You will still see it in copy-pasted embed codes from video platforms, and it still works, but the modern form is a `fullscreen` entry in `allow`. If both are present the `allow` list is the one to read. ## What this attribute is not It is worth fencing the answer. `allow` on an `<iframe>` governs what the *embedded* document may use. It is not a way to grant your own page anything, it does not affect what the frame may request over the network, and it is unrelated to whether the framed site is willing to be framed at all — that is the framed site's own response-level decision, not something an embedder can assert from markup. ## A worked pairing Suppose you embed a third-party document-signing widget, served from `https://sign.example`, that needs a webcam for identity capture and needs to submit its own form: ```html <iframe src="https://sign.example/session/abc" sandbox="allow-scripts allow-forms allow-same-origin" allow="camera 'src'" referrerpolicy="strict-origin" loading="lazy" title="Document signing"></iframe> ``` Read the element as three separate decisions. `sandbox` says which baseline capabilities this document keeps — here scripting, form submission, and its own origin, which is acceptable precisely because `sign.example` is a different origin from the embedder. `allow` says which powerful feature is delegated, scoped to the frame's own origin so a navigation elsewhere loses it. `referrerpolicy`, `loading` and `title` are ordinary element attributes that have nothing to do with capability at all. Keeping those decisions distinct in your head is most of what the question is testing. ## Interview framing The likely probe after your definition is "so which one stops the frame running JavaScript?" — the answer is `sandbox`, via the absence of `allow-scripts`, and a candidate who reaches for `allow` there has the two attributes fused. The second likely probe is whether removing a feature from `allow` blocks a *same-origin* frame; by default a same-origin frame inherits the embedder's features, so the interesting control there is writing an explicit `'none'` allowlist rather than assuming omission is enough.
- Which of the two attributes stops a framed document from executing JavaScript?`sandbox` — specifically, sandboxing the frame without the `allow-scripts` token. The `allow` attribute has no say over script execution at all; it governs powerful features like camera, microphone, geolocation and fullscreen. Conflating the two is the standard mistake, and an interviewer often asks exactly this to check.
- What is the difference between allow="camera" and allow="camera 'src'" in practice?Very little, because `'src'` is the default allowlist for an entry in the attribute — both scope the delegation to the origin of the frame's `src`. Writing it explicitly documents the intent, and it contrasts usefully with `allow="camera *"`, which keeps the delegation alive even if the frame navigates to some other origin.
- If the embedding page has already been denied camera access by the user, does allow="camera" help the frame?No. `allow` delegates a permission the embedder holds; it cannot create one. If the top-level page has no camera access, there is nothing to pass down and the frame is denied too. Delegation also does not skip the user prompt — it only removes the structural block that denies cross-origin frames by default.
saying these in an interview costs you the question
- Thinks allow re-enables scripting the way allow-scripts does
- Believes allow can grant a frame more than the page itself has
- Writes tokens comma-separated instead of semicolon-separated
- Assumes cross-origin frames get camera access without delegation
- Treats allowfullscreen as unrelated to the allow attribute