O elemento <iframe> de HTML representa um contexto de navegação integrado, efetivamente incorporando outra página HTML na página atual. No HTML 4.01, um documento poderá conter um head e um body ou um head e uma frameset, mas não ambos um body e uma frameset. Contudo, uma <iframe> pode ser utilizada dentro de um corpo de documento normal. Cada contexto de navegação tem o seu próprio histórico da sessão e documento ativo. O contexto de navegação que contém o conteúdo incorporado é chamado de contexto de navegação fonte. O contexto de navegação de nível superior (que não tem fonte) é geralmente a janela do navegador.

Categorias de conteúdo Flow content, phrasing content, embedded content, interactive content, palpable content.
Conteúdo permitido Fallback content, i.e. content that is normally not rendered, but that browsers not supporting the <iframe> element will render.
Omissão de etiqueta None, both the starting and ending tag are mandatory.
Fontes permitidas Any element that accepts embedded content.
Funções ARIA permitidas application, document, img
Interface DOM HTMLIFrameElement

Atributos

Este elemento inclui os atributos globais.

align Deprecated since HTML4.01, Obsolete since HTML5
The alignment of this element with respect to the surrounding context.
allowfullscreen
This attribute can be set to true if the frame is allowed to be placed into full screen mode by calling its Element.requestFullscreen() method. If this isn't set, the element can't be placed into full screen mode.
allowpaymentrequest
This attribute can be set to true if the contents of a cross-origin <iframe> should be allowed to invoke the Payment Request API.
frameborder HTML 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.
height
Indicates the height of the frame HTML5 in CSS pixels, or HTML 4.01 in pixels or as a percentage.
longdesc HTML 4 only
A URI of a long description of the frame. Due to widespread misuse, this is not helpful for non-visual browsers.
marginheight HTML 4 only
The amount of space in pixels between the frame's content and its top and bottom margins.
marginwidth HTML 4 only
The amount of space in pixels between the frame's content and its left and right margins.
mozallowfullscreen
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 element.mozRequestFullScreen() method. If this isn't set, the element can't be placed into full screen mode.
webkitallowfullscreen
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 element.webkitRequestFullScreen() method. If this isn't set, the element can't be placed into full screen mode.
name
A name for the embedded browsing context (or frame). This can be used as the value of the target attribute of an <a>, <form> or <base> element, or the formtarget attribute of an <input> or <button> element. It can also be used as the value of the windowName parameter in the window.open() method.
referrerpolicy
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.
scrolling HTML 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.
sandbox HTML5 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.
  • allow-top-navigation-by-user-activation: Allows the embedded browsing context to navigate (load) content to the top-level browsing context only when initiated by a user gesture. If this keyword is not used, this operation is not allowed.

Nota:

  • 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.
  • 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.
src
The URL of the page to embed. Use 'about:blank' for empty pages that conform to Same-Origin Policy.
srcdoc HTML5 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.
width
Indicates the width of the frame HTML5 in CSS pixels, or HTML 4.01 in pixels or as a percentage.

Scripting

Inline frames, like <frame> elements, enter the window.frames pseudo-array.

From the DOM iframe element, scripts can get access to the 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 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 Window.postMessage().

Exemplos

Aqui estão alguns exemplos que demonstram a utilização do elemento  <iframe>.

Uma <iframe> simples

é um exemplo básico de uma <iframe> em ação. Depois de criar a frame, quando o utilizador clica em um botão, o seu título é obtido e exibido num alerta.

HTML

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

Resultado

Abrir uma hiperligação numa <iframe> em outro saeparador

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

HTML

<base target="_blank">
<iframe id="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>

Resultado

Resultado

Exemplo Live

Notas

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

Especificações

Especificação Estado Comentário
Referrer Policy
The definition of 'referrerpolicy attribute' in that specification.
Candidate Recommendation Added the referrerpolicy attribute.
HTML Living Standard
The definition of '<iframe>' in that specification.
Living Standard  
HTML5
The definition of '<iframe>' in that specification.
Recommendation  
HTML 4.01 Specification
The definition of '<iframe>' in that specification.
Recommendation  
Screen Orientation API Working Draft Adds allow-orientation-lock to the sandbox attribute.
Presentation API
The definition of 'allow-presentation' in that specification.
Candidate Recommendation Adds allow-presentation to the sandbox attribute

Compatibilidade de navegador

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 1Edge Full support YesFirefox Full support Yes
Notes
Full support Yes
Notes
Notes The resize CSS property doesn't have any effect on this element due to bug 680823.
IE Full support YesOpera Full support YesSafari Full support Yes
Notes
Full support Yes
Notes
Notes Safari has a bug that prevents iframes from loading if the iframe element was hidden when added to the page. iframeElement.src = iframeElement.src should cause it to load the iframe.
WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support Yes
Notes
Full support Yes
Notes
Notes The resize CSS property doesn't have any effect on this element due to bug 680823.
Opera Android Full support YesSafari iOS Full support Yes
Notes
Full support Yes
Notes
Notes Safari has a bug that prevents iframes from loading if the iframe element was hidden when added to the page. iframeElement.src = iframeElement.src should cause it to load the iframe.
Samsung Internet Android Full support Yes
align
Deprecated
Chrome Full support 1Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
allow
Experimental
Chrome Full support 60Edge No support NoFirefox No support NoIE No support NoOpera Full support 47Safari Full support 11.1WebView Android Full support 60Chrome Android Full support 60Edge Mobile No support NoFirefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android No support No
allowfullscreenChrome Full support 27
Full support 27
Full support 17
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge Full support YesFirefox Full support 18
Full support 18
Full support 9
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE Full support 11
Prefixed
Full support 11
Prefixed
Prefixed Implemented with the vendor prefix: ms
Opera Full support YesSafari Full support 7
Full support 7
Full support Yes
Prefixed
Prefixed Implemented with the vendor prefix: webkit
WebView Android ? Chrome Android ? Edge Mobile Full support YesFirefox Android Full support 18
Full support 18
Full support 9
Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android No support NoSafari iOS Full support 7
Full support 7
Full support Yes
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Samsung Internet Android ?
allowpaymentrequest
Experimental
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
frameborder
Deprecated
Chrome Full support 1Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
heightChrome Full support 1Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
longdesc
Deprecated
Chrome Full support 1Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
marginheight
Deprecated
Chrome Full support 1Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
marginwidthChrome Full support 1Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
nameChrome Full support 1Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
referrerpolicyChrome Full support 51Edge No support NoFirefox Full support 50IE No support NoOpera Full support 38Safari Full support 11.1WebView Android Full support 51Chrome Android Full support 51Edge Mobile No support NoFirefox Android Full support 50Opera Android Full support 38Safari iOS No support NoSamsung Internet Android Full support 7.2
scrolling
Deprecated
Chrome Full support 1Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
sandboxChrome Full support 4Edge Full support YesFirefox Full support 17IE Full support 10Opera Full support 15Safari Full support 5WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 17Opera Android ? Safari iOS Full support 4.2Samsung Internet Android Full support Yes
sandbox="allow-popups"Chrome Full support YesEdge Full support YesFirefox Full support 28IE ? Opera ? Safari ? WebView Android ? Chrome Android ? Edge Mobile No support NoFirefox Android Full support 27Opera Android ? Safari iOS ? Samsung Internet Android ?
sandbox="allow-popups-to-escape-sandbox"Chrome Full support 46Edge No support NoFirefox Full support 49IE No support NoOpera Full support 32Safari ? WebView Android Full support 46Chrome Android Full support 46Edge Mobile No support NoFirefox Android Full support 49Opera Android Full support 32Safari iOS ? Samsung Internet Android Full support 5.0
sandbox="allow-modals"Chrome ? Edge No support NoFirefox Full support 49IE No support NoOpera ? Safari ? WebView Android ? Chrome Android ? Edge Mobile No support NoFirefox Android Full support 49Opera Android ? Safari iOS ? Samsung Internet Android ?
sandbox="allow-presentation"Chrome Full support 53Edge No support NoFirefox Full support 50IE No support NoOpera Full support 40Safari ? WebView Android No support NoChrome Android Full support 53Edge Mobile No support NoFirefox Android Full support 50Opera Android Full support 40Safari iOS ? Samsung Internet Android Full support 6.0
sandbox="allow-storage-access-by-user-activation"
ExperimentalNon-standard
Chrome No support NoEdge No support NoFirefox Full support 65
Disabled
Full support 65
Disabled
Disabled From version 65: this feature is behind the dom.storage_access.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera No support NoSafari Full support 11.1
Notes
Full support 11.1
Notes
Notes Currently only available on macOS High Sierra 10.13.4 beta, and in Safari Technology Preview 47+.
WebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 65
Disabled
Full support 65
Disabled
Disabled From version 65: this feature is behind the dom.storage_access.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android No support NoSafari iOS Full support 11.1
Notes
Full support 11.1
Notes
Notes Currently only available on iOS 11.3 beta.
Samsung Internet Android ?
sandbox="allow-top-navigation-by-user-activation"Chrome Full support 58Edge No support NoFirefox No support NoIE No support NoOpera Full support 45Safari ? WebView Android Full support 58Chrome Android Full support 58Edge Mobile No support NoFirefox Android No support NoOpera Android Full support 45Safari iOS ? Samsung Internet Android Full support 7.0
srcChrome Full support 1Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
srcdocChrome Full support 20Edge No support NoFirefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android ? Chrome Android ? Edge Mobile No support NoFirefox Android Full support 25Opera Android ? Safari iOS ? Samsung Internet Android ?
widthChrome Full support 1Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
mozbrowser
Non-standard
Chrome No support NoEdge No support NoFirefox No support No
Notes
No support No
Notes
Notes See bug 1318532
Notes Available only to WebExtensions.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support No
Notes
No support No
Notes
Notes See bug 1318532
Notes Available only to WebExtensions.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

Etiquetas do documento e contribuidores

Contribuidores para esta página: vicenterocha, mansil
Última atualização por: vicenterocha,