SOLFIND
Web Lens
Portal home

<iframe> HTML inline frame element - HTML | MDN

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/iframe • 214 KB fetched
Open original page


<iframe> HTML inline frame element - HTML | MDN * Skip to main content * Skip to search HTML HTML: Markup language HTML reference * Elements * Global attributes * Attributes * See all… HTML guides * Responsive images * HTML cheatsheet * Date & time formats * See all… Markup languages * SVG * MathML * XML CSS CSS: Styling language CSS reference * Properties * Selectors * At-rules * Values * See all… CSS guides * Box model * Animations * Flexbox * Colors * See all… Layout cookbook * Column layouts * Centering an element * Card component * See all… JavaScript JS JavaScript: Scripting language JS reference * Standard built-in objects * Expressions & operators * Statements & declarations * Functions * See all… JS guides * Control flow & error handing * Loops and iteration * Working with objects * Using classes * See all… Web APIs Web APIs: Programming interfaces Web API reference * File system API * Fetch API * Geolocation API * HTML DOM API * Push API * Service worker API * See all… Web API guides * Using the Web animation API * Using the Fetch API * Working with the History API * Using the Web speech API * Using web workers All All web technology Technologies * Accessibility * HTTP * URI * Web extensions * WebAssembly * WebDriver * See all… Topics * Media * Performance * Privacy * Security * Progressive web apps Learn Learn web development Frontend developer course * Getting started modules * Core modules * MDN Curriculum * Check out the video course from Scrimba, our partner Learn HTML * Structuring content with HTML module Learn CSS * CSS styling basics module * CSS layout module Learn JavaScript * Dynamic scripting with JavaScript module Tools Discover our tools * Playground * HTTP Observatory * Border-image generator * Border-radius generator * Box-shadow generator * Color format converter * Color mixer * Shape generator About Get to know MDN better * About MDN * Advertise with us * Community * MDN on GitHub Blog Toggle sidebar * Web * HTML * Reference * Elements * <iframe> Theme * OS default * Light * Dark English (US) Remember language Learn more * Deutsch * English (US) * Español * Français * 日本語 * Português (do Brasil) * 中文 (简体) <iframe> HTML inline frame element Baseline Widely available * This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015. * Some parts of this feature may have varying levels of support. * See full compatibility * Learn more The <iframe> HTML element represents a nested browsing context , embedding another HTML page into the current one. In this article * Try it * Attributes * Scripting * Positioning and scaling * error and load event behavior * Responsive <iframe> sizing * Accessibility * Examples * Technical summary * Specifications * Browser compatibility * See also Try it <iframe id="inlineFrameExample" title="Inline Frame Example" width="300" height="200" src="https://www.openstreetmap.org/export/embed.html?bbox=-0.004017949104309083%2C51.47612752641776%2C0.00030577182769775396%2C51.478569861898606&amp;layer=mapnik"> </iframe> iframe { border: 1px solid black; width: 100%; /* takes precedence over the width set with the HTML width attribute */ } Each embedded browsing context has its own document and allows URL navigations. The navigations of each embedded browsing context are linearized into the session history of the topmost browsing context. The browsing context that embeds the others is called the parent browsing context . The topmost browsing context — the one with no parent — is usually the browser window, represented by the Window object. Warning: Because each browsing context is a complete document environment, every <iframe> in a page requires increased memory and other computing resources. While theoretically you can use as many <iframe> s as you like, check for performance problems. Attributes This element includes the global attributes . allow Specifies a Permissions Policy for the <iframe> . The policy defines what features are available to the <iframe> (for example, access to the microphone, camera, battery, web-share, etc.) based on the origin of the request. See iframes in the Permissions-Policy topic for examples. Note: A Permissions Policy specified by the allow attribute implements a further restriction on top of the policy specified in the Permissions-Policy header. It doesn't replace it. allowfullscreen Set to true if the <iframe> can activate fullscreen mode by calling the requestFullscreen() method. Note: This attribute is considered a legacy attribute and redefined as allow="fullscreen *" . allowpaymentrequest Set to true if a cross-origin <iframe> should be allowed to invoke the Payment Request API . Note: This attribute is considered a legacy attribute and redefined as allow="payment *" . browsingtopics A boolean attribute that, if present, specifies that the selected topics for the current user should be sent with the request for the <iframe> 's source. credentialless Set to true to make the <iframe> credentialless, meaning that its content will be loaded in a new, ephemeral context. It doesn't have access to the network, cookies, and storage data associated with its origin. It uses a new context local to the top-level document lifetime. In return, the Cross-Origin-Embedder-Policy (COEP) embedding rules can be lifted, so documents with COEP set can embed third-party documents that do not. See IFrame credentialless for more details. csp A Content Security Policy enforced for the embedded resource. See HTMLIFrameElement.csp for details. height The height of the frame in CSS pixels. Default is 150 . loading Indicates when the browser should load the iframe: eager Load the iframe immediately on page load (this is the default value). lazy Defer loading of the iframe until it reaches a calculated distance from the visual viewport , as defined by the browser. The intent is to avoid using the network and storage bandwidth required to fetch the frame until the browser is reasonably certain that it will be needed. This improves the performance and cost in most typical use cases, in particular by reducing initial page load times. Loading is only deferred when JavaScript is enabled. This is an anti-tracking measure, because if a user agent supported lazy loading when scripting is disabled, it would still be possible for a site to track a user's approximate scroll position throughout a session, by strategically placing iframes in a page's markup such that a server can track how many iframes are requested and when. name A targetable name for the embedded browsing context. This can be used in the target attribute of the <a> , <form> , or <base> elements; the formtarget attribute of the <input> or <button> elements; or the windowName parameter in the window.open() method. In addition, the name becomes a property of the Window and Document objects, containing a reference to the embedded window or the element itself. privateToken Contains a string representation of an options object representing a private state token operation; this object has the same structure as the RequestInit dictionary's privateToken property. IFrames containing this attribute can initiate operations such as issuing or redeeming tokens when their embedded content is loaded. referrerpolicy Indicates which referrer to send when fetching the frame's resource: no-referrer The Referer header will not be sent. no-referrer-when-downgrade The Referer header will not be sent to origin s without TLS ( HTTPS ). origin The sent referrer will be limited to the origin of the referring page: its scheme , host , and port . origin-when-cross-origin The referrer sent to other origins will be limited to the scheme, the host, and the port. Navigations on the same origin will still include the path. same-origin A referrer will be sent for same origin , but cross-origin requests will contain no referrer information. strict-origin Only send the origin of the document as the referrer when the protocol security level stays the same (HTTPS→HTTPS), but don't send it to a less secure destination (HTTPS→HTTP). strict-origin-when-cross-origin (default) Send a full URL when performing a same-origin request, only send the origin when the protocol security level stays the same (HTTPS→HTTPS), and send no header to a less secure destination (HTTPS→HTTP). unsafe-url The referrer will include the origin and the path (but not the fragment , password , or username ). This value is unsafe , because it leaks origins and paths from TLS-protected resources to insecure origins. sandbox Controls the restrictions applied to the content embedded in the <iframe> . The value of the attribute can either be empty to apply all restrictions, or space-separated tokens to lift particular restrictions: allow-downloads Allows downloading files through an <a> or <area> element with the download attribute, as well as through the navigation that leads to a download of a file. This works regardless of whether the user clicked on the link, or JS code initiated it without user interaction. allow-forms Allows the page to submit forms. If this keyword is not used, a form will be displayed as normal, but submitting it will not trigger input validation, send data to a web server, or close a dialog. allow-modals Allows the page to open modal windows by Window.alert() , Window.confirm() , Window.print() and Window.prompt() , while opening a <dialog> is allowed regardless of this keyword. It also allows the page to receive BeforeUnloadEvent event. allow-orientation-lock Lets the resource lock the screen orientation . allow-pointer-lock Allows the page to use the Pointer Lock API . allow-popups Allows popups (created, for example, by Window.open() or target="_blank" ). If this keyword is not used, such functionality will silently fail. allow-popups-to-escape-sandbox Allows a sandboxed document to open a new browsing context without forcing the sandboxing flags upon it. This will allow, for example, a third-party advertisement to be safely sandboxed without forcing the same restrictions upon the page the ad links to. If this flag is not included, a redirected page, popup window, or new tab will be subject to the same sandbox restrictions as the originating <iframe> . allow-presentation Allows embedders to have control over whether an iframe can start a presentation session . allow-same-origin If this token is not used, the resource is treated as being from a special origin that always fails the same-origin policy (potentially preventing access to data storage/cookies and some JavaScript APIs). Note: When allow-same-origin is present, a same-origin parent document can still access and interact with the iframe's DOM even if allow-scripts is not set. The allow-scripts token only controls script execution within the embedded browsing context and does not affect DOM access from the parent. allow-scripts Allows the page to run scripts (but not create pop-up windows). If this keyword is not used, this operation is not allowed. allow-storage-access-by-user-activation Allows a document loaded in the <iframe> to use the Storage Access API to request access to unpartitioned cookies. allow-top-navigation Lets the resource navigate the top-level browsing context (the one named _top ). allow-top-navigation-by-user-activation Lets the resource navigate the top-level browsing context, but only if initiated by a user gesture. allow-top-navigation-to-custom-protocols Allows navigations to non- http protocols built into browser or registered by a website . This feature is also activated by allow-popups or allow-top-navigation keyword. Note: * When the embedded document has the same origin as the embedding page, it is strongly discouraged to use both allow-scripts and allow-same-origin , as that lets the embedded document remove the sandbox attribute — making it no more secure than not using the sandbox attribute at all. * Sandboxing is useless if the attacker can display content outside a sandboxed iframe — such as if the viewer opens the frame in a new tab. Such content should be also served from a separate origin to limit potential damage. Note: When redirecting the user, opening a popup window, or opening a new tab from an embedded page within an <iframe> with the sandbox attribute, the new browsing context is subject to the same sandbox restrictions. This can create issues — for example, if a page embedded within an <iframe> without a sandbox="allow-forms" or sandbox="allow-popups-to-escape-sandbox" attribute set on it opens a new site in a separate tab, form submission in that new browsing context will silently fail. src The URL of the page to embed. Use a value of about:blank to embed an empty page that conforms to the same-origin policy . Also note that programmatically removing an <iframe> 's src attribute (e.g., via Element.removeAttribute() ) causes about:blank to be loaded in the frame in Firefox (from version 65), Chromium-based browsers, and Safari/iOS. Note: The about:blank page uses the embedding document's URL as its base URL when resolving any relative URLs, such as anchor links. srcdoc Inline HTML to embed, overriding the src attribute. Its content should follow the syntax of a full HTML document, which includes the doctype directive, <html> , <body> tags, etc., although most of them can be omitted, leaving only the body content. This doc will have about:srcdoc as its location. If a browser does not support the srcdoc attribute, it will fall back to the URL in the src attribute. Note: The about:srcdoc page uses the embedding document's URL as its base URL when resolving any relative URLs, such as anchor links. width The width of the frame in CSS pixels. Default is 300 . Deprecated attributes These attributes are deprecated and may no longer be supported by all user agents. You should not use them in new content, and try to remove them from existing content. align The alignment of this element with respect to the surrounding context. frameborder The value 1 (the default) draws a border around this frame. The value 0 removes the border around this frame, but you should instead use the CSS property border to control <iframe> borders. longdesc A URL of a long description of the frame's content. Due to widespread misuse, this is not helpful for non-visual browsers. marginheight The amount of space in pixels between the frame's content and its top and bottom borders. marginwidth The amount of space in pixels between the frame's content and its left and right borders. scrolling Indicates when the browser should provide a scrollbar for the frame: auto Only when the frame's content is larger than its dimensions. yes Always show a scrollbar. no Never show a scrollbar. Scripting Inline frames, like <frame> elements, are included in the window.frames pseudo-array. With the DOM HTMLIFrameElement object, scripts can access the window object of the framed resource via the contentWindow property. The contentDocument property refers to the document inside the <iframe> , same as contentWindow.document . From the inside of a frame, a script can get a reference to its parent window with window.parent . Script access to a frame's content is subject to the same-origin policy . Scripts cannot access most properties in other window objects if the script was loaded from a different origin, including scripts inside a frame accessing the frame's parent. Cross-origin communication can be achieved using Window.postMessage() . Top navigation in cross-origin frames Scripts running in a same-origin frame can access the Window.top property and set window.top.location to redirect the top-level page to a new location. This behavior is referred to as "top navigation". A cross-origin frame is allowed to redirect the top-level page using top only if the frame has sticky activation . If top navigation is blocked, browsers may either prompt for user permission to redirect or report the error in the developer console (or both). This restriction by browsers is called framebusting intervention . What this means is that a cross-origin frame can't immediately redirect the top-level page — the user must have previously interacted with the frame or granted permission to redirect. A sandboxed frame blocks all top navigation unless the sandbox attribute values are set to allow-top-navigation or allow-top-navigation-by-user-activation . Note that top-navigation permissions are inherited, so a nested frame can perform a top navigation only if its parent frames are also allowed to. Positioning and scaling Being a replaced element , the <iframe> allows the position of the embedded document within its box to be adjusted using the object-position property. Note: The object-fit property has no effect on <iframe> elements. error and load event behavior The error and load events fired on <iframe> s could be used to probe the URL space of the local network's HTTP servers. Therefore, as a security precaution user agents do not fire the error event on <iframe> s, and the load event is always triggered even if the <iframe> content fails to load. Responsive <iframe> sizing For security and privacy reasons, <iframe> elements do not by default expose any information to the parent document about the size of the content in the document they are embedding. To enable responsive sizing of <iframe> elements based on their content, the <meta name="responsive-embedded-sizing"> tag can be included in an embedded document to opt it in to sharing its size information with the parent document. The frame-sizing CSS property can then be set on the <iframe> to cause it to adopt the same horizontal or vertical size as the

Links found on this page

  1. Skip to main content [direct]
  2. HTML: Markup language [direct]
  3. Elements [direct]
  4. Global attributes [direct]
  5. Attributes [direct]
  6. See all… [direct]
  7. Responsive images [direct]
  8. HTML cheatsheet [direct]
  9. Date & time formats [direct]
  10. See all… [direct]
  11. SVG [direct]
  12. MathML [direct]
  13. XML [direct]
  14. CSS: Styling language [direct]
  15. Properties [direct]
  16. Selectors [direct]
  17. At-rules [direct]
  18. Values [direct]
  19. See all… [direct]
  20. Box model [direct]
  21. Animations [direct]
  22. Flexbox [direct]
  23. Colors [direct]
  24. See all… [direct]
  25. Column layouts [direct]
  26. Centering an element [direct]
  27. Card component [direct]
  28. See all… [direct]
  29. JavaScript: Scripting language [direct]
  30. Standard built-in objects [direct]
  31. Expressions & operators [direct]
  32. Statements & declarations [direct]
  33. Functions [direct]
  34. See all… [direct]
  35. Control flow & error handing [direct]
  36. Loops and iteration [direct]
  37. Working with objects [direct]
  38. Using classes [direct]
  39. See all… [direct]
  40. Web APIs: Programming interfaces [direct]
  41. File system API [direct]
  42. Fetch API [direct]
  43. Geolocation API [direct]
  44. HTML DOM API [direct]
  45. Push API [direct]
  46. Service worker API [direct]
  47. Using the Web animation API [direct]
  48. Using the Fetch API [direct]
  49. Working with the History API [direct]
  50. Using the Web speech API [direct]
  51. Using web workers [direct]
  52. All web technology [direct]
  53. Accessibility [direct]
  54. HTTP [direct]
  55. URI [direct]
  56. Web extensions [direct]
  57. WebAssembly [direct]
  58. WebDriver [direct]
  59. Media [direct]
  60. Performance [direct]
  61. Privacy [direct]
  62. Security [direct]
  63. Progressive web apps [direct]
  64. Learn web development [direct]
  65. Getting started modules [direct]
  66. Core modules [direct]
  67. MDN Curriculum [direct]
  68. Check out the video course from Scrimba, our partner [direct]
  69. Structuring content with HTML module [direct]
  70. CSS styling basics module [direct]
  71. CSS layout module [direct]
  72. Dynamic scripting with JavaScript module [direct]
  73. Playground [direct]
  74. HTTP Observatory [direct]
  75. Border-image generator [direct]
  76. Border-radius generator [direct]
  77. Box-shadow generator [direct]
  78. Color format converter [direct]
  79. Color mixer [direct]
  80. Shape generator [direct]