Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1116505 of <iframe>

  • Revision slug: Web/HTML/Element/iframe
  • Revision title: <iframe>
  • Revision id: 1116505
  • Created:
  • Creator: jpmedley
  • Is current revision? No
  • Comment

Revision Content

{{HTMLRef}}

Summary

The HTML Inline Frame Element (<iframe>) represents a nested browsing context, effectively embedding another HTML page into the current page. In HTML 4.01, a document may contain a head and a body or a head and a frameset, but not both a body and a frameset. However, an <iframe> can be used within a normal document body. Each browsing context has its own session history and active document. The browsing context that contains the embedded content is called the parent browsing context. The top-level browsing context (which has no parent) is typically the browser window.

Content categories Flow content, phrasing content, embedded content, interactive content, palpable content.
Permitted content Special, see prose
Tag omission {{no_tag_omission}}
Permitted parent elements Any element that accepts embedded content.
DOM interface {{domxref("HTMLIFrameElement")}}

Attributes

This element includes the global attributes.

{{htmlattrdef("align")}} {{deprecated_inline("html4.01")}}, {{obsolete_inline("html5")}}
The alignment of this element with respect to the surrounding context.
{{htmlattrdef("allowfullscreen")}}
This attribute can be set to true if the frame is allowed to be placed into full screen mode by calling its {{domxref("Element.requestFullScreen()")}} method. If this isn't set, the element can't be placed into full screen mode.
{{htmlattrdef("frameborder")}} {{HTMLVersionInline(4)}} only
The value 1 (the default) tells the browser to draw a border between this frame and every other frame. The value 0 tells the browser not to draw a border between this frame and other frames.
{{htmlattrdef("height")}}
Indicates the height of the frame {{HTMLVersionInline(5)}} in CSS pixels, or {{HTMLVersionInline(4.01)}} in pixels or as a percentage.
{{htmlattrdef("longdesc")}} {{HTMLVersionInline(4)}} only
A URI of a long description of the frame. Due to widespread misuse, this is not helpful for non-visual browsers.
{{htmlattrdef("marginheight")}} {{HTMLVersionInline(4)}} only
The amount of space in pixels between the frame's content and its top and bottom margins.
{{htmlattrdef("marginwidth")}} {{HTMLVersionInline(4)}} only
The amount of space in pixels between the frame's content and its left and right margins.
{{htmlattrdef("mozallowfullscreen")}} {{non-standard_inline}} {{deprecated_inline}}
Use allowfullscreen instead. In Gecko 9.0 or later, this attribute can be set to true if the frame is allowed to be placed into full screen mode by calling its {{domxref("element.mozRequestFullScreen()")}} method. If this isn't set, the element can't be placed into full screen mode.
{{htmlattrdef("webkitallowfullscreen")}} {{non-standard_inline}} {{deprecated_inline}}
Use allowfullscreen instead. In Chrome 17 or later (and maybe earlier), this attribute can be set to true if the frame is allowed to be placed into full screen mode by calling its {{domxref("element.webkitRequestFullScreen()")}} method. If this isn't set, the element can't be placed into full screen mode.
{{htmlattrdef("mozapp")}} {{non-standard_inline}} {{B2GOnlyInline}}
For frames hosting an open web app, this specifies the URL of the app manifest. This ensures that the app is loaded with the right permissions. See Using the Browser API for details. Available in Gecko 13.0 and later.
{{htmlattrdef("mozbrowser")}} {{non-standard_inline}} {{B2GOnlyInline}}
Indicates that the frame is to appear like a top-level browser window to the embedded content. This means that {{domxref("window.top")}}, {{domxref("window.parent")}}, {{domxref("window.frameElement")}}, etc. will not reflect the frame hierarchy. This allows for a web browser UI to be implemented entirely with web technology, given the right permissions. See Using the Browser API for details. Available in Gecko 13.0 and later.
{{htmlattrdef("name")}}
A name for the embedded browsing context (or frame). This can be used as the value of the target attribute of an {{HTMLElement("a")}} or {{HTMLElement("form")}} element, or the formtarget attribute of an {{HTMLElement("input")}} or {{HTMLElement("button")}} element.
{{htmlattrdef("referrerpolicy")}} {{experimental_inline}}
A string indicating which referrer to use when fetching the resource:
  • "no-referrer" meaning that the Referer: header will not be sent.
  • "no-referrer-when-downgrade" meaning that no Referer: header will be sent when navigating to an origin without TLS (HTTPS). This is a user agent’s default behavior, if no policy is otherwise specified.
  • "origin" meaning that the referrer will be the origin of the page, that is roughly the scheme, the host and the port.
  • "origin-when-cross-origin" meaning that navigations to other origins will be limited to the scheme, the host and the port, while navigations on the same origin will include the referrer's path.
  • "unsafe-url" meaning that the referrer will include the origin and the path (but not the fragment, password, or username). This case is unsafe because it can leak origins and paths from TLS-protected resources to insecure origins.
{{htmlattrdef("remote")}} {{non-standard_inline}} {{B2GOnlyInline}}
Load the frame's page in a separate content process.
{{htmlattrdef("scrolling")}} {{HTMLVersionInline(4)}} only
Enumerated attribute indicating when the browser should provide a scroll bar (or other scrolling device) for the frame:
  • auto: Only when needed.
  • yes: Always provide a scroll bar.
  • no: Never provide a scroll bar.
{{htmlattrdef("sandbox")}} {{HTMLVersionInline(5)}} only
If specified as an empty string, this attribute enables extra restrictions on the content that can appear in the inline frame. The value of the attribute can either be an empty string (all the restrictions are applied), or a space-separated list of tokens that lift particular restrictions. Valid tokens are:
  • allow-forms: Allows the embedded browsing context to submit forms. If this keyword is not used, this operation is not allowed.
  • allow-modals: Allows the embedded browsing context to open modal windows.
  • allow-orientation-lock: Allows the embedded browsing context to disable the ability to lock the screen orientation.
  • allow-pointer-lock: Allows the embedded browsing context to use the Pointer Lock API.
  • allow-popups: Allows popups (like from window.open, target="_blank", showModalDialog). If this keyword is not used, that functionality will silently fail.
  • allow-popups-to-escape-sandbox:  Allows a sandboxed document to open new windows without forcing the sandboxing flags upon them. This will allow, for example, a third-party advertisement to be safely sandboxed without forcing the same restrictions upon a landing page.
  • allow-presentation: Allows embedders to have control over whether an iframe can start a presentation session.
  • allow-same-origin: Allows the content to be treated as being from its normal origin. If this keyword is not used, the embedded content is treated as being from a unique origin.
  • allow-scripts: Allows the embedded browsing context to run scripts (but not create pop-up windows). If this keyword is not used, this operation is not allowed.
  • allow-top-navigation: Allows the embedded browsing context to navigate (load) content to the top-level browsing context. If this keyword is not used, this operation is not allowed.

Note:

  • When the embedded document has the same origin as the main page, it is strongly discouraged to use both allow-scripts and allow-same-origin at the same time, as that allows the embedded document to programmatically remove the sandbox attribute. Although it is accepted, this case is no more secure than not using the sandbox attribute.
  • However the sandboxed iframe will not have write access to it's "document.domain" property, so you can still protect your parent document by executing "document.domain = document.domain;", see this document for more information about the "document.domain" property.
  • Sandboxing in general is only of minimal help if the attacker can arrange for the potentially hostile content to be displayed in the user's browser outside a sandboxed iframe. It is recommended that such content should be served from a separate dedicated domain, to limit the potential damage.
  • The sandbox attribute is not supported in Internet Explorer 9 and earlier versions.
{{htmlattrdef("src")}}
The URL of the page to embed.
{{htmlattrdef("srcdoc")}} {{HTMLVersionInline(5)}} only
The content of the page that the embedded context is to contain. This attribute is expected to generally be used together with the sandbox attribute. If a browser supports the srcdoc attribute, it will override the content specified in the src attribute (if present). If a browser does NOT support the srcdoc attribute, it will show the file specified in the src attribute instead (if present). Note that if the content of the attribute contains a script tag then a closing script tag is required for the script to run, even if nothing else comes after the script.
{{htmlattrdef("width")}}
Indicates the width of the frame {{HTMLVersionInline(5)}} in CSS pixels, or {{HTMLVersionInline(4.01)}} in pixels or as a percentage.

Scripting

Inline frames, like {{HTMLElement("frame")}} elements, enter the {{domxref("window.frames")}} pseudo-array.

From the DOM iframe element, scripts can get access to the {{domxref("window")}} object of the included HTML page via the contentWindow property. The contentDocument property refers to the document element inside the iframe (this is equivalent to contentWindow.document), but is not supported by Internet Explorer versions before IE8.

From the inside of a frame, a script can get a reference to the parent window via {{domxref("Window.parent")}}.

Scripts trying to access a frame's content are subject to the same-origin policy, and cannot access most of the properties in the other window object if it was loaded from a different domain. This also applies to a script inside a frame trying to access its parent window. Cross-domain communication can still be achieved with {{domxref("Window.postMessage()")}}.

Examples

Here are a few examples demonstrating the use of the <iframe> element.

A simple <iframe>

This is a basic example of an <iframe> in action. After creating the frame, when the user clicks a button, its title is retrieved and displayed in an alert.

HTML

<iframe src="https://mdn-samples.mozilla.org/snippets/html/iframe-simple-contents.html" width="400" height="300">
  <p>Your browser does not support iframes.</p>
</iframe>

Result

{{ EmbedLiveSample('Example1', '', '', '', 'Web/HTML/Element/iframe') }}

Open a link in an <iframe> in another tab

In this example, a Google map is displayed in a frame;

HTML

<base target="_blank">
<iframe id="Example2"
    name="Example2"
    title="Example2"
    width="400"
    height="300"
    frameborder="0"
    scrolling="no"
    marginheight="0"
    marginwidth="0"
    src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=es-419&amp;geocode=&amp;q=buenos+aires&amp;sll=37.0625,-95.677068&amp;sspn=38.638819,80.859375&amp;t=h&amp;ie=UTF8&amp;hq=&amp;hnear=Buenos+Aires,+Argentina&amp;z=11&amp;ll=-34.603723,-58.381593&amp;output=embed">
</iframe>

<br>
<small>
  <a href="https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=es-419&amp;geocode=&amp;q=buenos+aires&amp;sll=37.0625,-95.677068&amp;sspn=38.638819,80.859375&amp;t=h&amp;ie=UTF8&amp;hq=&amp;hnear=Buenos+Aires,+Argentina&amp;z=11&amp;ll=-34.603723,-58.381593" style="color:#0000FF;text-align:left"> See bigger map </a>
</small>

Result

{{ EmbedLiveSample('Example2', '', '', '', 'Web/HTML/Element/iframe') }}

Result

Live example

Notes

Starting in {{Gecko("6.0")}}, rendering of inline frames correctly respects the borders of their containing element when they're rounded using {{cssxref("border-radius")}}.

Specifications

Specification Status Comment
{{SpecName('Referrer Policy', '#referrer-policy-delivery-referrer-attribute', 'referrerpolicy attribute')}} {{Spec2('Referrer Policy')}} Added the referrerpolicy attribute.
{{SpecName('HTML WHATWG', 'the-iframe-element.html#the-iframe-element', '<iframe>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5 W3C', 'embedded-content-0.html#the-iframe-element', '<iframe>')}} {{Spec2('HTML5 W3C')}}  
{{SpecName('HTML4.01', 'present/frames.html#h-16.5', '<iframe>')}} {{Spec2('HTML4.01')}}  
{{SpecName('Screen Orientation')}} {{Spec2('Screen Orientation')}} Adds allow-orientation-lock to the sandbox attribute.
{{SpecName('Presentation','#sandboxing-and-the-allow-presentation-keyword','allow-presentation')}} {{Spec2('Presentation')}} Adds allow-presentation to the sandbox attribute

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(1.0)}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}[2] {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}[3]
sandbox {{CompatChrome(4.0)}} {{CompatVersionUnknown}} {{CompatGeckoDesktop("17.0")}} 10 15 5
srcdoc {{CompatChrome(20.0)}} {{CompatNo}} {{CompatGeckoDesktop("25.0")}} {{CompatNo}} 15 6
allowfullscreen {{CompatChrome(17.0)}} {{property_prefix("webkit")}}
{{CompatChrome(27.0)}}
{{CompatVersionUnknown}} {{CompatGeckoDesktop("9.0")}} {{property_prefix("moz")}}
{{CompatGeckoDesktop("18.0")}}

11 {{property_prefix("ms")}}

{{CompatVersionUnknown}} {{CompatVersionUnknown}} {{property_prefix("webkit")}}
7
sandbox="allow-popups" {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatGeckoDesktop("27.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
sandbox="allow-popups-to-escape-sandbox" {{CompatChrome(46.0)}} {{CompatNo}} {{CompatGeckoDesktop("49.0")}} {{CompatUnknown}} 32 {{CompatUnknown}}
sandbox="allow-modals" {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoDesktop("49.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
referrerpolicy {{CompatChrome(51.0)}} {{CompatNo}} {{CompatGeckoDesktop("42.0")}} [1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
sandbox="allow-presentation" {{CompatChrome(53.0)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

{{CompatOpera(40)}}

{{CompatUnknown}}
Feature Android Android Webview Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatVersionUnknown}}

{{CompatVersionUnknown}}

{{CompatVersionUnknown}}[2] {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

{{CompatVersionUnknown}}

sandbox 2.2

{{CompatVersionUnknown}}

{{CompatGeckoMobile("17.0")}} 10 {{CompatNo}} 4.2

{{CompatVersionUnknown}}

srcdoc {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile("25.0")}} {{CompatNo}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
allowfullscreen {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile("9.0")}} {{property_prefix("moz")}}
{{CompatGeckoMobile("18.0")}}
{{CompatNo}} {{CompatNo}} {{CompatVersionUnknown}} {{property_prefix("webkit")}}
7
{{CompatUnknown}}
sandbox="allow-popups" {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile("27.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
sandbox="allow-popups-to-escape-sandbox" {{CompatNo}} {{CompatChrome(46)}} {{CompatGeckoMobile("49.0")}} {{CompatUnknown}} 32 {{CompatUnknown}} {{CompatChrome(46.0)}}
sandbox="allow-modals" {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile("49.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
referrerpolicy {{CompatNo}} {{CompatChrome(51.0)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatChrome(51.0)}}
sandbox="allow-presentation" {{CompatNo}} {{CompatNo}} {{CompatUnknown}} {{CompatUnknown}}

{{CompatOperaMobile(40)}}

{{CompatUnknown}} {{CompatChrome(53.0)}}

[1] Implemented as referrer and behind the flag network.http.enablePerElementReferrer. Renamed to referrerpolicy in Firefox 45.

[2] The {{cssxref("resize")}} CSS property doesn't have any effect on this element due to {{bug("680823")}}.

[3] Safari has a well-known bug that prevents iframes from loading if the iframe element was hidden when added to the page. iframeElement.src = iframElement.src should cause it to load the iframe.

Revision Source

<div>{{HTMLRef}}</div>

<h2 id="Summary">Summary</h2>

<p>The <dfn>HTML Inline Frame Element</dfn> (<strong><code>&lt;iframe&gt;</code></strong>) represents a nested browsing context, effectively embedding another HTML page into the current page. In HTML 4.01, a document may contain a <code>head</code> and a <code>body</code> or a <code>head</code> and a <code>frameset</code>, but not both a <code>body</code> and a <code>frameset</code>. However, an <code>&lt;iframe&gt;</code> can be used within a normal document body. Each browsing context has its own session history and active document. The browsing context that contains the embedded content is called the <dfn>parent</dfn> browsing context. The <dfn>top-level</dfn> browsing context (which has no parent) is typically the browser window.</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row"><a href="/en-US/docs/HTML/Content_categories">Content categories</a></th>
   <td><a href="/en-US/docs/HTML/Content_categories#Flow_content">Flow content</a>, <a href="/en-US/docs/HTML/Content_categories#Phrasing_content">phrasing content</a>, embedded content, interactive content, palpable content.</td>
  </tr>
  <tr>
   <th scope="row">Permitted content</th>
   <td>Special, see prose</td>
  </tr>
  <tr>
   <th scope="row">Tag omission</th>
   <td>{{no_tag_omission}}</td>
  </tr>
  <tr>
   <th scope="row">Permitted parent elements</th>
   <td>Any element that accepts embedded content.</td>
  </tr>
  <tr>
   <th scope="row">DOM interface</th>
   <td>{{domxref("HTMLIFrameElement")}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Attributes">Attributes</h2>

<p>This element includes the <a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes">global attributes</a>.</p>

<dl>
 <dt>{{htmlattrdef("align")}} {{deprecated_inline("html4.01")}}, {{obsolete_inline("html5")}}</dt>
 <dd>The alignment of this element with respect to the surrounding context.</dd>
 <dt>{{htmlattrdef("allowfullscreen")}}</dt>
 <dd>This attribute can be set to <code>true</code> if the frame is allowed to be placed into full screen mode by calling its {{domxref("Element.requestFullScreen()")}} method. If this isn't set, the element can't be placed into full screen mode.</dd>
 <dt>{{htmlattrdef("frameborder")}} {{HTMLVersionInline(4)}} only</dt>
 <dd>The value 1 (the default) tells the browser to draw a border between this frame and every other frame. The value 0 tells the browser not to draw a border between this frame and other frames.</dd>
 <dt>{{htmlattrdef("height")}}</dt>
 <dd>Indicates the height of the frame {{HTMLVersionInline(5)}} in CSS pixels, or {{HTMLVersionInline(4.01)}} in pixels or as a percentage.</dd>
 <dt>{{htmlattrdef("longdesc")}} {{HTMLVersionInline(4)}} only</dt>
 <dd>A URI of a long description of the frame. Due to widespread misuse, this is not helpful for non-visual browsers.</dd>
 <dt>{{htmlattrdef("marginheight")}} {{HTMLVersionInline(4)}} only</dt>
 <dd>The amount of space in pixels between the frame's content and its top and bottom margins.</dd>
 <dt>{{htmlattrdef("marginwidth")}} {{HTMLVersionInline(4)}} only</dt>
 <dd>The amount of space in pixels between the frame's content and its left and right margins.</dd>
 <dt>{{htmlattrdef("mozallowfullscreen")}} {{non-standard_inline}} {{deprecated_inline}}</dt>
 <dd>Use <code><strong>allowfullscreen</strong></code> instead. In Gecko 9.0 or later, this attribute can be set to <code>true</code> if the frame is allowed to be placed into full screen mode by calling its {{domxref("element.mozRequestFullScreen()")}} method. If this isn't set, the element can't be placed into full screen mode.</dd>
 <dt>{{htmlattrdef("webkitallowfullscreen")}} {{non-standard_inline}} {{deprecated_inline}}</dt>
 <dd>Use <code><strong>allowfullscreen</strong></code> instead. In Chrome 17 or later (and maybe earlier), this attribute can be set to <code>true</code> if the frame is allowed to be placed into full screen mode by calling its {{domxref("element.webkitRequestFullScreen()")}} method. If this isn't set, the element can't be placed into full screen mode.</dd>
 <dt>{{htmlattrdef("mozapp")}} {{non-standard_inline}} {{B2GOnlyInline}}</dt>
 <dd>For frames hosting an <a href="/en-US/docs/Apps" title="OpenWebApps">open web app</a>, this specifies the URL of the <a href="/en-US/docs/Apps/Manifest" title="Apps/Manifest">app manifest</a>. This ensures that the app is loaded with the right permissions. See <a href="/en-US/docs/DOM/Using_the_Browser_API" title="DOM/Using_the_Browser_API">Using the Browser API</a> for details. Available in Gecko 13.0 and later.</dd>
 <dt>{{htmlattrdef("mozbrowser")}} {{non-standard_inline}} {{B2GOnlyInline}}</dt>
 <dd>Indicates that the frame is to appear like a top-level browser window to the embedded content. This means that {{domxref("window.top")}}<span id="summary_alias_container"><span id="short_desc_nonedit_display">, </span></span>{{domxref("window.parent")}}<span id="summary_alias_container"><span id="short_desc_nonedit_display">, </span></span>{{domxref("window.frameElement")}},<span id="summary_alias_container"><span id="short_desc_nonedit_display"> etc. will <em>not</em> reflect the frame hierarchy. This allows for a web browser UI to be implemented entirely with web technology, given the right permissions.</span></span> See <a href="/en-US/docs/DOM/Using_the_Browser_API" title="DOM/Using_the_Browser_API">Using the Browser API</a> for details. Available in Gecko 13.0 and later.</dd>
 <dt id="name-attribute">{{htmlattrdef("name")}}</dt>
 <dd>A name for the embedded browsing context (or frame). This can be used as the value of the <code><strong>target</strong></code> attribute of an {{HTMLElement("a")}} or {{HTMLElement("form")}} element, or the formtarget attribute of an {{HTMLElement("input")}} or {{HTMLElement("button")}} element.</dd>
 <!-- including anchor to attr-referrer because it used to be called "referrer" -->
 <dt id="attr-referrer">{{htmlattrdef("referrerpolicy")}} {{experimental_inline}}</dt>
 <dd>A string indicating which referrer to use when fetching the resource:
 <ul>
  <li><code>"no-referrer"</code> meaning that the <code>Referer:</code> header will not be sent.</li>
  <li>"<code>no-referrer-when-downgrade</code>" meaning that no <code>Referer:</code> header will be sent when navigating to an origin without TLS (HTTPS). This is a user agent’s default behavior, if no policy is otherwise specified.</li>
  <li><code>"origin"</code> meaning that the referrer will be the origin of the page, that is roughly the scheme, the host and the port.</li>
  <li>"origin-when-cross-origin" meaning that navigations to other origins will be limited to the scheme, the host and the port, while navigations on the same origin will include the referrer's path.</li>
  <li><code>"unsafe-url"</code> meaning that the referrer will include the origin and the path (but not the fragment, password, or username). This case is unsafe because it can leak origins and paths from TLS-protected resources to insecure origins.</li>
 </ul>
 </dd>
 <dt>{{htmlattrdef("remote")}} {{non-standard_inline}} {{B2GOnlyInline}}</dt>
 <dd>Load the frame's page in a separate content process.</dd>
 <dt>{{htmlattrdef("scrolling")}} {{HTMLVersionInline(4)}} only</dt>
 <dd>Enumerated attribute indicating when the browser should provide a scroll bar (or other scrolling device) for the frame:
 <ul>
  <li><code>auto</code>: Only when needed.</li>
  <li><code>yes</code>: Always provide a scroll bar.</li>
  <li><code>no</code>: Never provide a scroll bar.</li>
 </ul>
 </dd>
 <dt>{{htmlattrdef("sandbox")}} {{HTMLVersionInline(5)}} only</dt>
 <dd>If specified as an empty string, this attribute enables extra restrictions on the content that can appear in the inline frame. The value of the attribute can either be an empty string (all the restrictions are applied), or a space-separated list of tokens that lift particular restrictions. Valid tokens are:
 <ul>
  <li><code>allow-forms</code>: Allows the embedded browsing context to submit forms. If this keyword is not used, this operation is not allowed.</li>
  <li><code>allow-modals</code>: Allows the embedded browsing context to open modal windows.</li>
  <li><code>allow-orientation-lock</code>: Allows the embedded browsing context to disable the ability to lock the screen orientation.</li>
  <li><code>allow-pointer-lock</code>: Allows the embedded browsing context to use the <a href="/en-US/docs/WebAPI/Pointer_Lock">Pointer Lock API</a>.</li>
  <li><code>allow-popups</code>: Allows popups (like from <code>window.open</code>, <code>target="_blank"</code>, <code>showModalDialog</code>). If this keyword is not used, that functionality will silently fail.</li>
  <li><code>allow-popups-to-escape-sandbox</code>:&nbsp; Allows a sandboxed document to open new windows without forcing the sandboxing flags upon them. This will allow, for example, a third-party advertisement to be safely sandboxed without forcing the same restrictions upon a landing page.</li>
  <li><code>allow-presentation</code>: Allows embedders to have control over whether an iframe can start a presentation session.</li>
  <li><code>allow-same-origin</code>: Allows the content to be treated as being from its normal origin. If this keyword is not used, the embedded content is treated as being from a unique origin.</li>
  <li><code>allow-scripts</code>: Allows the embedded browsing context to run scripts (but not create pop-up windows). If this keyword is not used, this operation is not allowed.</li>
  <li><code>allow-top-navigation</code>: Allows the embedded browsing context to navigate (load) content to the top-level browsing context. If this keyword is not used, this operation is not allowed.</li>
 </ul>

 <div class="note">
 <p><strong>Note:</strong></p>

 <ul>
  <li>When the embedded document has the same origin as the main page, it is strongly discouraged to use both <code>allow-scripts</code> and <code>allow-same-origin</code> at the same time, as that allows the embedded document to programmatically remove the <code>sandbox</code> attribute. Although it is accepted, this case is no more secure than not using the <code>sandbox</code> attribute.</li>
  <li>However the sandboxed iframe will not have write access to it's "document.domain" property, so you can still protect your parent document by executing "document.domain = document.domain;", see <a href="/en-US/docs/Web/API/Document/domain">this document</a> for more information about the "document.domain" property.</li>
  <li>Sandboxing in general is only of minimal help if the attacker can arrange for the potentially hostile content to be displayed in the user's browser outside a sandboxed <code>iframe</code>. It is recommended that such content should be served from a <em>separate dedicated domain</em>, to limit the potential damage.</li>
  <li>The <code>sandbox</code> attribute is not supported in Internet Explorer 9 and earlier versions.</li>
 </ul>
 </div>
 </dd>
 <dt>{{htmlattrdef("src")}}</dt>
 <dd>The URL of the page to embed.</dd>
 <dt>{{htmlattrdef("srcdoc")}} {{HTMLVersionInline(5)}} only</dt>
 <dd>The content of the page that the embedded context is to contain. This attribute is expected to generally be used together with the <code>sandbox</code> attribute. If a browser supports the <code>srcdoc</code> attribute, it will override the content specified in the <code>src</code> attribute (if present). If a browser does NOT support the <code>srcdoc</code> attribute, it will show the file specified in the <code>src</code> attribute instead (if present). Note that if the content of the attribute contains a script tag then a closing script tag is required for the script to run, even if nothing else comes after the script.</dd>
 <dt>{{htmlattrdef("width")}}</dt>
 <dd>Indicates the width of the frame {{HTMLVersionInline(5)}} in CSS pixels, or {{HTMLVersionInline(4.01)}} in pixels or as a percentage.</dd>
</dl>

<h2 id="Scripting">Scripting</h2>

<p>Inline frames, like {{HTMLElement("frame")}} elements, enter the {{domxref("window.frames")}} pseudo-array.</p>

<p>From the DOM <code>iframe</code> element, scripts can get access to the {{domxref("window")}} object of the included HTML page via the <code>contentWindow</code> property. The <code>contentDocument</code> property refers to the document element inside the <code>iframe</code> (this is equivalent to <code>contentWindow.document</code>), but is not supported by Internet Explorer versions before IE8.</p>

<p>From the inside of a frame, a script can get a reference to the parent window via {{domxref("Window.parent")}}.</p>

<p>Scripts trying to access a frame's content are subject to the <a href="/en-US/docs/Same_origin_policy_for_JavaScript" title="Same origin policy for JavaScript">same-origin policy</a>, and cannot access most of the properties in the other window object if it was loaded from a different domain. This also applies to a script inside a frame trying to access its parent window. Cross-domain communication can still be achieved with {{domxref("Window.postMessage()")}}.</p>

<h2 id="Examples">Examples</h2>

<p>Here are a few examples demonstrating the use of the <code>&lt;iframe&gt;</code> element.</p>

<h3 id="Example1" name="Example1">A simple <code>&lt;iframe&gt;</code></h3>

<p>This is a basic example of an <code>&lt;iframe&gt;</code> in action. After creating the frame, when the user clicks a button, its title is retrieved and displayed in an alert.</p>

<h4 id="HTML">HTML</h4>

<div id="htmlOutputWrapper">
<pre class="brush: html">
&lt;iframe src="https://mdn-samples.mozilla.org/snippets/html/iframe-simple-contents.html" width="400" height="300"&gt;
  &lt;p&gt;Your browser does not support iframes.&lt;/p&gt;
&lt;/iframe&gt;</pre>
</div>

<h4 id="Result">Result</h4>

<p>{{ EmbedLiveSample('Example1', '', '', '', 'Web/HTML/Element/iframe') }}</p>

<h3 id="Example2" name="Example2">Open a link in an <code>&lt;iframe&gt;</code> in another tab</h3>

<p>In this example, a Google map is displayed in a frame;</p>

<h4 id="HTML_2">HTML</h4>

<pre class="brush: html">
&lt;base target="_blank"&gt;
&lt;iframe id="Example2"
    name="Example2"
    title="Example2"
    width="400"
    height="300"
    frameborder="0"
    scrolling="no"
    marginheight="0"
    marginwidth="0"
    src="https://maps.google.com/maps?f=q&amp;amp;source=s_q&amp;amp;hl=es-419&amp;amp;geocode=&amp;amp;q=buenos+aires&amp;amp;sll=37.0625,-95.677068&amp;amp;sspn=38.638819,80.859375&amp;amp;t=h&amp;amp;ie=UTF8&amp;amp;hq=&amp;amp;hnear=Buenos+Aires,+Argentina&amp;amp;z=11&amp;amp;ll=-34.603723,-58.381593&amp;amp;output=embed"&gt;
&lt;/iframe&gt;

&lt;br&gt;
&lt;small&gt;
  &lt;a href="https://maps.google.com/maps?f=q&amp;amp;source=embed&amp;amp;hl=es-419&amp;amp;geocode=&amp;amp;q=buenos+aires&amp;amp;sll=37.0625,-95.677068&amp;amp;sspn=38.638819,80.859375&amp;amp;t=h&amp;amp;ie=UTF8&amp;amp;hq=&amp;amp;hnear=Buenos+Aires,+Argentina&amp;amp;z=11&amp;amp;ll=-34.603723,-58.381593" style="color:#0000FF;text-align:left"&gt; See bigger map &lt;/a&gt;
&lt;/small&gt;</pre>

<h4 id="Result_2">Result</h4>

<p>{{ EmbedLiveSample('Example2', '', '', '', 'Web/HTML/Element/iframe') }}</p>

<h4 id="Result_3">Result</h4>

<p><a href="https://jsfiddle.net/pablofiumara/mCfAe/">Live example</a></p>

<h2 id="Notes">Notes</h2>

<div class="note">
<p>Starting in {{Gecko("6.0")}}, rendering of inline frames correctly respects the borders of their containing element when they're rounded using {{cssxref("border-radius")}}.</p>
</div>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('Referrer Policy', '#referrer-policy-delivery-referrer-attribute', 'referrerpolicy attribute')}}</td>
   <td>{{Spec2('Referrer Policy')}}</td>
   <td>Added the <code>referrerpolicy</code> attribute.</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'the-iframe-element.html#the-iframe-element', '&lt;iframe&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'embedded-content-0.html#the-iframe-element', '&lt;iframe&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'present/frames.html#h-16.5', '&lt;iframe&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('Screen Orientation')}}</td>
   <td>{{Spec2('Screen Orientation')}}</td>
   <td>Adds <code>allow-orientation-lock</code> to the <code>sandbox</code> attribute.</td>
  </tr>
  <tr>
   <td>{{SpecName('<span style="line-height:1.5">Presentation','#sandboxing-and-the-allow-presentation-keyword','allow-presentation')}}</span></td>
   <td>{{Spec2('Presentation')}}</td>
   <td>Adds <code>allow-presentation</code> to the <code>sandbox</code> attribute</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(1.0)}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}[2]</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}[3]</td>
  </tr>
  <tr>
   <td><code>sandbox</code></td>
   <td>{{CompatChrome(4.0)}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop("17.0")}}</td>
   <td>10</td>
   <td>15</td>
   <td>5</td>
  </tr>
  <tr>
   <td><code>srcdoc</code></td>
   <td>{{CompatChrome(20.0)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop("25.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>15</td>
   <td>6</td>
  </tr>
  <tr>
   <td><code>allowfullscreen</code></td>
   <td>{{CompatChrome(17.0)}} {{property_prefix("webkit")}}<br />
    {{CompatChrome(27.0)}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop("9.0")}} {{property_prefix("moz")}}<br />
    {{CompatGeckoDesktop("18.0")}}</td>
   <td>
    <p>11&nbsp;{{property_prefix("ms")}}</p>
   </td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}} {{property_prefix("webkit")}}<br />
    7</td>
  </tr>
  <tr>
   <td><code>sandbox="allow-popups"</code></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop("27.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>sandbox="allow-popups-to-escape-sandbox"</code></td>
   <td>{{CompatChrome(46.0)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop("49.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>32</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>sandbox="allow-modals"</code></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("49.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>referrerpolicy</code></td>
   <td>{{CompatChrome(51.0)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop("42.0")}} [1]</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>sandbox="allow-presentation"</code></td>
   <td>{{CompatChrome(53.0)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>
    <p>{{CompatOpera(40)}}</p>
   </td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>
    <p>{{CompatVersionUnknown}}</p>
   </td>
   <td>{{CompatVersionUnknown}}[2]</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>
    <p>{{CompatVersionUnknown}}</p>
   </td>
  </tr>
  <tr>
   <td><code>sandbox</code></td>
   <td>2.2</td>
   <td>
    <p>{{CompatVersionUnknown}}</p>
   </td>
   <td>{{CompatGeckoMobile("17.0")}}</td>
   <td>10</td>
   <td>{{CompatNo}}</td>
   <td>4.2</td>
   <td>
    <p>{{CompatVersionUnknown}}</p>
   </td>
  </tr>
  <tr>
   <td><code>srcdoc</code></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("25.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>allowfullscreen</code></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("9.0")}} {{property_prefix("moz")}}<br />
    {{CompatGeckoMobile("18.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}} {{property_prefix("webkit")}}<br />
    7</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>sandbox="allow-popups"</code></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("27.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>sandbox="allow-popups-to-escape-sandbox"</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(46)}}</td>
   <td>{{CompatGeckoMobile("49.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>32</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(46.0)}}</td>
  </tr>
  <tr>
   <td><code>sandbox="allow-modals"</code></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("49.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>referrerpolicy</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(51.0)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(51.0)}}</td>
  </tr>
  <tr>
   <td><code>sandbox="allow-presentation"</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>
    <p>{{CompatOperaMobile(40)}}</p>
   </td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(53.0)}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1]&nbsp;Implemented as <code>referrer</code> and behind the flag <code>network.http.enablePerElementReferrer</code>. Renamed to <code>referrerpolicy</code> in Firefox 45.</p>

<p>[2] The {{cssxref("resize")}} CSS property doesn't have any effect on this element due to {{bug("680823")}}.</p>

<p>[3] Safari has a well-known <a href="https://www.quirksmode.org/bugreports/archives/2005/02/hidden_iframes.html">bug</a> that prevents iframes from loading if the iframe element was hidden when added to the page. iframeElement.src = iframElement.src should cause it to load the iframe.</p>
Revert to this revision