Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the iframe tag allowed in the head tag according to the W3C?

Tags:

html

iframe

w3c

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?

like image 251
Arie Avatar asked Nov 11 '14 09:11

Arie


People also ask

Which tag is used for iframe?

The HTML <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.

Where do you put iframe in HTML?

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.

Can we use iframe in HTML5?

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.

Is iframe tag still used?

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.”


1 Answers

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

like image 93
Quentin Avatar answered Oct 31 '22 10:10

Quentin