HTML5: Can HEAD tag contain IFRAME tag?

(W Andrzejczak) #1


I’m trying to investigate why Google in Google Tag Manager is embedding DoubleClick Floodlight (Tracking Pixels) as IFRAME in top of HEAD section.
Yes, it is not a bug in Tag Manager. It is how it works.

I’ve found that in “Permitted content” section it says something about IFRAME but whole description is a bit difficult to understand.

My Questions:

  1. Does HTML5 spec. allows to use IFRAME in HEAD section at all?
  2. If We can Put IFRAME in HEAD section that what restrictions we have there?


(SteveVS) #2

No an iframe cannot be used for that…mind if i ask what your trying to do?

(Chris Mills) #3

You are right that this is a bit confusing; we could certainly do with improving this, but I’m not 100% sure what the it should be changed to.

I think it is trying to say that if the <head> is inside a document pointed to by an <iframe> element’s srcdoc attribute, then it doesn’t need to contain any child elements. But in all other cases it needs to contain at least one, which is a <title>.

But I’ve never seen an iframe being used inside the head before; that is weird. Have you done any testing?

(W Andrzejczak) #4

Hi Chris,

Thanks for your mail.
I’m seeing IFRAME tags in HEAD section every day :slight_smile:

Google Tag Manager is injecting IFRAME via JavaScript to HEAD.
Examples where you can see it:

Try to find DoubleClick Floodlight IFRAME with source containing

And to be clear. This doesn’t affect measurements. Everything works without any issue.

What is also funny is that if I try to validate a test static HTML page where I’ve hardcoded IFRAME, validator is not throwing error that IFRAME is in wrong place. Instead it throws other error. So at this again it is hard to say if it is correct implementation or not.

(SteveVS) #5

wow, I guess I learn something different everyday! Thanks for the examples, @w.andrzejczak

(SteveVS) #6

At the bottom of the docs on the MDN site, iframe isn’t listed as one of the permitted tags?


If the element is an iframe srcdoc, or if title information is available from a higher level protocol, zero or more elements of metadata content.
Otherwise, one or more elements of metadata content where exactly one is a element.

I think the above is referring to the content of the iframe, do you think that is what is trying to be relayed above, @chrismills and @w.andrzejczak?

(Eric Shepherd) #7

According to the specification, the only elements permitted inside are metadata elements, and those are:

  • <base>
  • <link>
  • <meta>
  • <noscript>
  • <style>
  • <template>
  • <title>

This is another delightful example of advertising tools playing fast and loose with the rules.

Eric Shepherd
Senior Technical Writer
MDN Web Docs: