💎 PREMIUM: Multipage/iframe embed object.html - Complete Album!
HTML
Living Standard — Last Updated 17 December 2025
4.8.5 The
iframe element
Support in all current engines.
Opera15+Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android14+
Support in all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+
Support in all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+
Support in all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+
Support in all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+
- Categories:
- Flow content.
- Phrasing content.
- Embedded content.
- Interactive content.
- Palpable content.
- Phrasing content.
- Contexts in which this element can be used:
- Where embedded content is expected.
- Content model:
- Nothing.
- Tag omission in text/html:
- Neither tag is omissible.
- Content attributes:
- Global attributes
src— Address of the resourcesrcdoc— A document to render in theiframename— Name of content navigablesandbox— Security rules for nested contentallow— Permissions policy to be applied to theiframe's contentsallowfullscreen— Whether to allow theiframe's contents to userequestFullscreen()width— Horizontal dimensionheight— Vertical dimensionreferrerpolicy— Referrer policy for fetches initiated by the elementloading— Used when determining loading deferral - Accessibility considerations:
- For authors.
- For implementers.
- DOM interface:
-
[Exposed =Window ]interface HTMLIFrameElement :HTMLElement { [HTMLConstructor ]constructor (); [CEReactions ,ReflectURL ]attribute USVString src ; [CEReactions ]attribute (TrustedHTML or DOMString )srcdoc ; [CEReactions ,Reflect ]attribute DOMString name ; [SameObject ,PutForwards =value ,Reflect ]readonly attribute DOMTokenList sandbox ; [CEReactions ,Reflect ]attribute DOMString allow ; [CEReactions ,Reflect ]attribute boolean allowFullscreen ; [CEReactions ,Reflect ]attribute DOMString width ; [CEReactions ,Reflect ]attribute DOMString height ; [CEReactions ]attribute DOMString referrerPolicy ; [CEReactions ]attribute DOMString loading ;readonly attribute Document ?contentDocument ;readonly attribute WindowProxy ?contentWindow ;Document ?getSVGDocument (); // also has obsolete members };
The iframe element represents its content navigable.
The src attribute
gives the URL of a page that the element's content navigable is to
contain. The attribute, if present, must be a valid non-empty URL potentially surrounded by
spaces. If the itemprop attribute is specified on an
iframe element, then the src attribute must
also be specified.
Support in all current engines.
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android?
The srcdoc
attribute gives the content of the page that the element's content navigable is to
contain. The value of the attribute is used to construct an iframe srcdoc document, which is a Document whose
URL matches about:srcdoc.
The srcdoc attribute, if present, must have a value
using the HTML syntax that consists of the following syntactic components, in the
given order:
- Any number of comments and ASCII whitespace.
- Optionally, a DOCTYPE.
- Any number of comments and ASCII whitespace.
- The document element, in the form of an
htmlelement. - Any number of comments and ASCII whitespace.
The above requirements apply in XML documents as well.
Here a blog uses the srcdoc attribute in conjunction
with the sandbox attribute described below to provide
users of user agents that support this feature with an extra layer of protection from script
injection in the blog post comments:
< article >
< h1 > I got my own magazine!</ h1 >
< p > After much effort, I've finally found a publisher, and so now I
have my own magazine! Isn't that awesome?! The first issue will come
out in September, and we have articles about getting food, and about
getting in boxes, it's going to be great!</ p >
< footer >
< p > Written by < a href = "/users/cap" > cap</ a > , 1 hour ago.
</ footer >
< article >
< footer > Thirteen minutes ago, < a href = "/users/ch" > ch</ a > wrote: </ footer >
< iframe sandbox srcdoc = "<p>did you get a cover picture yet?" ></ iframe >
</ article >
< article >
< footer > Nine minutes ago, < a href = "/users/cap" > cap</ a > wrote: </ footer >
< iframe sandbox srcdoc = "<p>Yeah, you can see it <a href="/gallery?mode=cover&amp;page=1">in my gallery</a>." ></ iframe >
</ article >
< article >
< footer > Five minutes ago, < a href = "/users/ch" > ch</ a > wrote: </ footer >
< iframe sandbox srcdoc = "<p>hey that's earl's table.
<p>you should get earl&amp;me on the next cover." ></ iframe >
</ article >
Notice the way that quotes have to be escaped (otherwise the srcdoc attribute would end prematurely), and the way raw
ampersands (e.g. in URLs or in prose) mentioned in the sandboxed content have to be
doubly escaped — once so that the ampersand is preserved when originally parsing
the srcdoc attribute, and once more to prevent the
ampersand from being misinterpreted when parsing the sandboxed content.
Furthermore, notice that since the DOCTYPE is optional in
iframe srcdoc documents, and the html,
head, and body elements have optional
start and end tags, and the title element is also optional in iframe srcdoc
documents, the markup in a srcdoc attribute can be
relatively succinct despite representing an entire document, since only the contents of the
body element need appear literally in the syntax. The other elements are still
present, but only by implication.
In the HTML syntax, authors need only remember to use U+0022
QUOTATION MARK characters (") to wrap the attribute contents and then to escape all U+0026
AMPERSAND (&) and U+0022 QUOTATION MARK (") characters, and to specify the sandbox attribute, to ensure safe embedding of content. (And
remember to escape ampersands before quotation marks, to ensure quotation marks become "
and not &quot;.)
In XML the U+003C LESS-THAN SIGN character (<) needs to be escaped as well. In order to prevent attribute-value normalization, some of XML's whitespace characters — specifically U+0009 CHARACTER TABULATION (tab), U+000A LINE FEED (LF), and U+000D CARRIAGE RETURN (CR) — also need to be escaped. [XML]
If the src attribute and the srcdoc attribute are both specified together, the srcdoc attribute takes priority. This allows authors to provide
a fallback URL for legacy user agents that do not support the srcdoc attribute.
The iframe HTML element post-connection steps, given
insertedNode, are:
Create a new child navigable for insertedNode.
If insertedNode has a
sandboxattribute, then parse the sandboxing directive given the attribute's value and insertedNode'siframesandboxing flag set.Process the
iframeattributes for insertedNode, with initialInsertion set to true.
The iframe HTML element removing steps, given
removedNode, are to destroy a child navigable given
removedNode.
This happens without any unload events firing
(the element's content document is destroyed, not unloaded).
Although iframes are processed while in a shadow tree,
per the above, several other aspects of their behavior are not well-defined with regards to
shadow trees. See issue #763 for more
detail.
Whenever an iframe element with a non-null content navigable has its
srcdoc attribute set, changed, or removed, the user
agent must process the iframe attributes.
Similarly, whenever an iframe element with a non-null content
navigable but with no srcdoc attribute specified
has its src attribute set, changed, or removed, the user
agent must process the iframe attributes.
To process the iframe attributes for an element element,
with an optional boolean initialInsertion (default false):
-
If element's
srcdocattribute is specified, then:Set element's current navigation was lazy loaded boolean to false.
-
If the will lazy load element steps given element return true, then:
Set element's lazy load resumption steps to the rest of this algorithm starting with the step labeled navigate to the srcdoc resource.
Set element's current navigation was lazy loaded boolean to true.
Start intersection-observing a lazy loading element for element.
Return.
-
Navigate to the srcdoc resource: