Are HTML5 custom elements allowed in <HEAD>

Viewed 283

I am trying to write some HTML5 standards compliant code, where certain scripts need to be run only after the user has consented to cookies.

The html code looks like this, where the consent-script element, works exactly the same as the script element, however holds off loading the script until the consent has been given.

<head>

<consent-script src="myscript.js"></consent-script>

</head>

Everything works fine in all browsers, However when I attempt to validate this using https://validator.w3.org/ , the custom-element tag apparently closes the head section, and generates a pile of errors.

Looking at the specifications, I can't see any reason why custom-elements cant be used in the section. But I am not sure.

My question is, can HTML5 custom-elements be used in HEAD? If I can, then its a bug in the validator service. If not, then I will have to find another way of not running a script until the right moment.

Thanks.

EDIT. Further investigation (Thanks @Danny'365CSI'Engelman) leads me to believe that even a browser is moving the custom element out of the head section, into the body section.

Some mock up code:

The source is:

<!DOCTYPE html>
<html>
<head>
  <my-custom-elem></my-custom-elem>
  <!-- other tags in the HEAD -->
</head>
<body>this is the body
</body>
</html>

Yet, chrome developer tools gives me:

<html>
<head>
</head>
<body>
  <my-custom-elem></my-custom-elem>
  <!-- other tags in the HEAD -->

  this is the body

</body></html>
0 Answers
Related