Can the <link>
tag in HTML be outside the <head>
element?
If not, why?
I want to know if the tag can be placed outside of the <head>
element
Can the <link>
tag in HTML be outside the <head>
element?
If not, why?
I want to know if the tag can be placed outside of the <head>
element
2
Answers
First of all, you should learn to do your own research afford. Such questions can be easily answered with own research effort by reading the documentation (API).
Specifically, there are 2 institutions that specify everything within the web stack:
The easiest way to read into the documentation as a user is to use the MDN Web Docs (Mozilla Developer Network Web Documentation).
If you look at the MDN Web Docs for the link tag you will find a section for Specifications which in this case will lead to the WHATWG Specifications for the link tag.
The WHATWG Specification explicit states:
That means that according to the official specifications the link tag can be used within the body in certain cases.
It can, under some conditions.
If it has a
rel
attribute that is body-ok, i.e. one ofdns-prefetch
,modulepreload
,pingback
,preconnect
,prefetch
,preload
,prerender
, andstylesheet
, or if it has anitemprop
attribute, then it is allowed in the body. If it doesn’t meet either of this conditions, it is not allowed in the body, but it won’t be a parse error either, and thus won’t be moved away in the DOM, but its action may not work.