US <iframe>: The Inline Frame element - HTML | MDN https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe Archived on 2026-04-24 14:01 UTC : The Inline Frame element - HTML | MDNSkip to search: The Inline Frame elementBaselineWidely availableThis 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 compatibilityReport feedbackTheHTMLelement represents a nestedbrowsing context, embedding another HTML page into the current one.Try itid="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&layer=mapnik">iframe {border: 1px solid black;width: 100%; /* takes precedence over the width set with the HTML width attribute */Each embedded browsing context has its owndocumentand allows URL navigations. The navigations of each embedded browsing context are linearized into thesession historyof thetopmostbrowsing context. The browsing context that embeds the others is called theparent browsing context. Thetopmostbrowsing context — the one with no parent — is usually the browser window, represented by theWindowobject.Warning:Because each browsing context is a complete document environment, everyin a page requires increased memory and other computing resources. While theoretically you can use as manys as you like, check for performance problems.AttributesThis element includes theglobal attributesallowSpecifies aPermissions Policyfor the. The policy defines what features are available to the(for example, access to the microphone, camera, battery, web-share, etc.) based on the origin of the request.Seeiframesin thePermissions-Policytopic for examples.Note:A Permissions Policy specified by theallowattribute implements a further restriction on top of the policy specified in thePermissions-Policyheader. It doesn't replace it.allowfullscreenSet totrueif thecan activate fullscreen mode by calling therequestFullscreen()method.Note:This attribute is considered a legacy attribute and redefined asallow="fullscreen *"allowpaymentrequestDeprecatedNon-standardSet totrueif a cross-originshould be allowed to invoke thePayment Request APINote:This attribute is considered a legacy attribute and redefined asallow="payment *"browsingtopicsNon-standardDeprecatedA boolean attribute that, if present, specifies that the selected topics for the current user should be sent with the request for the's source. SeeUsing the Topics APIfor more details.credentiallessExperimentalSet totrueto make thecredentialless, 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, theCross-Origin-Embedder-Policy(COEP) embedding rules can be lifted, so documents with COEP set can embed third-party documents that do not. SeeIFrame credentiallessfor more details.cspExperimentalContent Security Policyenforced for the embedded resource. SeeHTMLIFrameElement.cspfor details.heightThe height of the frame in CSS pixels. Default is150loadingIndicates when the browser should load the iframe:eagerLoad the iframe immediately on page load (this is the default value).lazyDefer loading of the iframe until it reaches a calculated distance from thevisual 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.nameA targetable name for the embedded browsing context. This can be used in thetargetattribute of the, orelements; theformtargetattribute of theorelements; or thewindowNameparameter in thewindow.open()method. In addition, the name becomes a property of theWindowandDocumentobjects, containing a reference to the embedded window or the element itself.privateTokenExperimentalContains a string representation of an options object representing aprivate state tokenoperation; this object has the same structure as theRequestInitdictionary'sprivateTokenproperty. IFrames containing this attribute can initiate operations such as issuing or redeeming tokens when their embedded content is loaded.referrerpolicyIndicates whichreferrerto send when fetching the frame's resource:no-referrerTheRefererheader will not be sent.no-referrer-when-downgradeTheRefererheader will not be sent toorigins withoutTLSHTTPS).originThe sent referrer will be limited to the origin of the referring page: itsschemehost, andportorigin-when-cross-originThe 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-originA referrer will be sent forsame origin, but cross-origin requests will contain no referrer information.strict-originOnly 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-urlThe referrer will include the originandthe path (but not thefragmentpassword, orusername).This value is unsafe, because it leaks origins and paths from TLS-protected resources to insecure origins.sandboxControls the restrictions applied to the content embedded in the. The value of the attribute can either be empty to apply all restrictions, or space-separated tokens to lift particular restrictions:allow-downloadsAllows downloading files through anorelement with theattribute, 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-formsAllows 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-modalsAllows the page to open modal windows byWindow.alert()Window.confirm()Window.print()andWindow.prompt(), while opening ais allowed regardless of this keyword. It also allows the page to receiveBeforeUnloadEventevent.allow-orientation-lockLets the resourcelock the screen orientationallow-pointer-lockAllows the page to use thePointer Lock APIallow-popupsAllows popups (created, for example, byWindow.open()ortarget="_blank"). If this keyword is not used, such functionality will silently fail.allow-popups-to-escape-sandboxAllows 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 originatingallow-presentationAllows embedders to have control over whether an iframe can start apresentation sessionallow-same-originIf this token is not used, the resource is treated as being from a special origin that always fails thesame-origin policy(potentially preventing access todata storage/cookiesand some JavaScript APIs).Note:Whenallow-same-originis present, a same-origin parent document can still access and interact with the iframe's DOM even ifallow-scriptsis not set. Theallow-scriptstoken only controls script execution within the embedded browsing context and does not affect DOM access from the parent.allow-scriptsAllows 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-activationExperimentalAllows a document loaded in theto use theStorage Access APIto request access to unpartitioned cookies.allow-top-navigationLets the resource navigate the top-level browsing context (the one named_top).allow-top-navigation-by-user-activationLets the resource navigate the top-level browsing context, but only if initiated by a user gesture.allow-top-navigation-to-custom-protocolsAllows navigations to non-httpprotocols built into browser orregistered by a website. This feature is also activated byallow-popupsorallow-top-navigationkeyword.Note:When the embedded document has the same origin as the embedding page, it isstrongly discouragedto use bothallow-scriptsandallow-same-origin, as that lets the embedded document remove thesandboxattribute — making it no more secure than not using thesandboxattribute at all.Sandboxing is useless if the attacker can display content outside a sandboxediframe— such as if the viewer opens the frame in a new tab. Such content should be also served from aseparate originto limit potential damage.Note:When redirecting the user, opening a popup window, or opening a new tab from an embedded page within anwith thesandboxattribute, the new browsing context is subject to the samesandboxrestrictions. This can create issues — for example, if a page embedded within anwithout asandbox="allow-forms"orsandbox="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.srcThe URL of the page to embed. Use a value ofabout:blankto embed an empty page that conforms to thesame-origin policy. Also note that programmatically removing an's src attribute (e.g., viaElement.removeAttribute()) causesabout:blankto be loaded in the frame in Firefox (from version 65), Chromium-based browsers, and Safari/iOS.Note:Theabout:blankpage uses the embedding document's URL as its base URL when resolving any relative URLs, such as anchor links.srcdocInline HTML to embed, overriding thesrcattribute. Its content should follow the syntax of a full HTML document, which includes the doctype directive,tags, etc., although most of them can be omitted, leaving only the body content. This doc will haveabout:srcdocas its location. If a browser does not support thesrcdocattribute, it will fall back to the URL in thesrcattribute.Note:Theabout:srcdocpage uses the embedding document's URL as its base URL when resolving any relative URLs, such as anchor links.widthThe width of the frame in CSS pixels. Default is300Deprecated attributesThese 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.alignDeprecatedThe alignment of this element with respect to the surrounding context.frameborderDeprecatedThe value(the default) draws a border around this frame. The valueremoves the border around this frame, but you should instead use the CSS propertyborderto controlborders.longdescDeprecatedA URL of a long description of the frame's content. Due to widespread misuse, this is not helpful for non-visual browsers.marginheightDeprecatedThe amount of space in pixels between the frame's content and its top and bottom borders.marginwidthDeprecatedThe amount of space in pixels between the frame's content and its left and right borders.scrollingDeprecatedIndicates when the browser should provide a scrollbar for the frame:autoOnly when the frame's content is larger than its dimensions.yesAlways show a scrollbar.noNever show a scrollbar.ScriptingInline frames, likeelements, are included in thewindow.framespseudo-array.With the DOMHTMLIFrameElementobject, scripts can access thewindowobject of the framed resource via thecontentWindowproperty. ThecontentDocumentproperty refers to thedocumentinside the, same ascontentWindow.documentFrom the inside of a frame, a script can get a reference to its parent window withwindow.parentScript access to a frame's content is subject to thesame-origin policyScripts cannot access most properties in otherwindowobjects 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 usingWindow.postMessage()Top navigation in cross-origin framesScripts running in a same-origin frame can access theWindow.topproperty and setwindow.top.locationto 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 usingtoponly if the frame hassticky activationIf 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 calledframebusting interventionWhat 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 thesandboxattribute values are set toallow-top-navigationorallow-top-navigation-by-user-activationNote 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 scalingBeing areplaced element, theallows the position of the embedded document within its box to be adjusted using theobject-positionproperty.Note:Theobject-fitproperty has no effect onelements.errorandloadevent behaviorTheerrorandloadevents fired ons 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 theerrorevent ons, and theloadevent is always triggered even if thecontent fails to load.People navigating with assistive technology such as a screen reader can use thetitleattributeon anto label its content. The title's value should concisely describe the embedded content:htmltitle="Wikipedia page for Avocados"src="https://en.wikipedia.org/wiki/Avocado">Without this title, they have to navigate into theto determine what its embedded content is. This context shift can be confusing and time-consuming, especially for pages with multiples and/or if embeds contain interactive content like video or audio.ExamplesA basic This example embeds the page atin an iframe. This is a common use case of iframes: to embed content from another site. For example, the live sample itself, and thetry itexample at the top, are bothembeds of content from another MDN site.HTMLhtmlsrc="https://example.org"title="iframe Example 1"width="400"height="300">ResultEmbedding source code in an This example directly renders source code in an iframe. This can be used as a technique to prevent script injection when displaying user-generated content, when combined with thesandboxattribute.Note that when usingsrcdoc, any relative URLs in the embedded content will be resolved relative to the URL of the embedding page. If you want to use anchor links that point to places in the embedded content, you need to explicitly specifyabout:srcdocas the base URL.HTMLhtmlsandboxsrcdoc="There are two ways to use the iframe element:To embed content from another pageTo embed user-generated contentEmbedding content from another pageUse the src attribute to specify the URL of the page to embed:<iframe src="https://example.org"></iframe>Embedding user-generated contentUse the srcdoc attribute to specify the content to embed. This post is already an example!width="500"height="250">Here's how to write escape sequences when usingsrcdocFirst, write the HTML out, escaping anything you would escape in a normal HTML document (such as, etc.).<andrepresent the exact same character in thesrcdocattribute. Therefore, to make it an actual escape sequence in the HTML document, replace any ampersands () with&. For example,<becomes<, and&becomes&Replace any double quotes () with"to prevent thesrcdocattribute from being prematurely terminated (if you useinstead, then you should replacewith'instead). This step happens after the previous one, so"generated in this step doesn't become"ResultTechnical summaryContent categoriesFlow contentphrasing content, embedded content, interactive content, palpable content.Permitted contentNone.Tag omissionNone, both the starting and ending tags are mandatory.Permitted parentsAny element that accepts embedded content.Implicit ARIA roleNo corresponding rolePermitted ARIA rolesapplicationdocumentimgnonepresentationDOM interfaceHTMLIFrameElementSpecificationsSpecificationHTML# the-iframe-elementBrowser compatibilitySee alsoCSP: frame-ancestorsPrivacy, permissions, and information securityHelp improve MDNLearn how to contributeThis page was last modified onApr 5, 2026byMDN contributorsView this page on GitHubReport a problem with this content Same domain → Similar titles →
sandboxsrcdoc="There are two ways to use the iframe element:To embed content from another pageTo embed user-generated contentEmbedding content from another pageUse the src attribute to specify the URL of the page to embed:<iframe src="https://example.org"></iframe>Embedding user-generated contentUse the srcdoc attribute to specify the content to embed. This post is already an example!width="500"height="250">