Sandbox permissions and third-party privacy
An embedded page runs in its own browsing context, but permissions should be constrained and external requests should be considered.
✓ What you will learn in this topic
- Explain the purpose of Sandbox permissions and third-party privacy in a real HTML document.
- Choose and apply the elements shown in both examples.
- Recognize the specific mistake described in this lesson.
Concept explanation
Sandbox applies restrictions to an iframe. Permissions such as allowing scripts or forms should be added only when the embedded content needs them; combining permissions can weaken isolation. Referrer policy controls how much referring URL information is sent. A frame can still contact its own service and reveal visitor network information, so sandboxing does not replace privacy review or consent. Prefer a simple outbound link when the embed is not essential.
Syntax
Start with sandbox restrictions and grant only documented capabilities; set referrerpolicy when reducing referrer data is appropriate.
Example 1: a small page
An empty sandbox attribute applies strong restrictions; the embedded page may need fewer features as a result.
<iframe src=\"https://example.org/guide\" title=\"Embedded visitor guide\" sandbox=\"\" loading=\"lazy\"></iframe>Expected result: The frame loads in a restricted environment; features blocked by sandbox will not operate.
Example 2: a practical page
This grants specific capabilities often required by a player but must be reviewed because script and same-origin permissions together weaken isolation.
<iframe src=\"https://video.example.org/player/42\" title=\"Interview with the museum curator\" sandbox=\"allow-scripts allow-same-origin\" referrerpolicy=\"no-referrer\" loading=\"lazy\"></iframe>Expected result: The third-party player receives only its declared sandbox capabilities and no referrer URL.
Common mistakes
Do not embed an external page without considering its permissions, privacy behavior, and whether a link is sufficient.
Best practices
Give iframe a descriptive title, use the narrowest sandbox permissions that work, and defer noncritical embeds.
Practice exercise
Design an event page that provides a direct map link and an optional embedded map with an accessible title, lazy loading, and limited permissions.
Lesson summary
- Use minimal sandbox permissions and remember that privacy review extends beyond the frameâs DOM access.
- Give iframe a descriptive title, use the narrowest sandbox permissions that work, and defer noncritical embeds.
Knowledge check
What is the safest starting point for iframe sandbox permissions?
Show the explanation
Start with restrictions enabled and add only the narrow permissions required by the trusted embed.
Practical example
html<iframe src=\"https://example.org/guide\" title=\"Embedded visitor guide\" sandbox=\"\" loading=\"lazy\"></iframe>
Expected result:
The frame loads in a restricted environment; features blocked by sandbox will not operate.
Hands-on practice task
Design an event page that provides a direct map link and an optional embedded map with an accessible title, lazy loading, and limited permissions.
In this section
Other lessons in Embedding External Content
Broaden your knowledge