I am in the middle of a discussion with two developers about placing an <iframe>
in the <head>
of an HTML page. This is needed for a TAG.
According to developer 1, the tag may not be placed in the header because the tag creates an iframe to load another tag, and iframes are flow content and must be placed in the <body>
according to the W3C specifications for HTML 5.1.
Developer 2 says the iframe is allowed in any context where embedded content is allowed. Some embedded content may also be interactive content (e.g. audio tags), and these must be in the body; however, the iframe we add has no content and is not interactive, so based on his understanding of the spec, it may show up anywhere in the document.
More information about the W3C specification can be found here: http://www.w3.org/TR/html5/dom.html#kinds-of-content
The W3C validator does not throw a error or warning with an iframe in the head, but this is not enough for developer 1.
Mu question is simple: if we place the iframe without content in the head, will this be a violation of the specifications or does the specification leave room for interpretation like developer 2 says?
The HTML <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.
Complete HTML/CSS Course 2022 The <iframe> tag is not somehow related to <frameset> tag, instead, it can appear anywhere in your document. The <iframe> tag defines a rectangular region within the document in which the browser can display a separate document, including scrollbars and borders.
The <iframe> element is still valid in HTML5. Depending on what exact interaction you need there might be different APIs. For example there's the postMessage method which allows you to achieve cross domain javascript interaction.
Google Says Do Not Use iFrames In fact, even Google says, don't do it – straight from its developer site: “We recommend that you avoid the use of iFrames to display content.”
According to developer 1 the tag may not be placed in the header because the tag creates an IFRAME to load another tag and IFRAME's are flow content an must be placed in the BODY according to the W3C specifications for HTML 5.1.
This is correct
Developer 2 says the IFRAME is allowed in any context where Embedded content is allowed.
Correct
Some embedded content may also be Interactive Content (eg: Audio tags), and these must be in the BODY,
Correct
however, the IFRAME we add has no content
Incorrect.
The child nodes of the iframe element provide alternative content for browsers without support for frames. This is content.
The iframe itself is a replaced element. It generates a visual UI on the page for displaying another document. This is content.
and is not interactive,
The specification explicitly lists it as being interactive content.
so based on his understanding of the spec, it may show up anywhere in the document.
Incorrect.
The W3C validator does not throw a error or warning, but this is not enough for developer 1.
An iframe, not being allowed in the head, will implicitly end the head element and start the body element, so you will only get an error if you follow it with content that is allowed only in the head or an explicit head end tag or body start tag.
If we place the IFRAME without content
There is no such thing
in the HEAD will this be a violation of the specifications
Putting any iframe in the head will violate the specification
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With