Reputation: 267077
Is it possible/good practice to use <link href"">
to include stylesheets outside of the <head>
tag, or do they only work / should they be only used in <head>
?
Upvotes: 30
Views: 16463
Reputation: 10919
In HTML5, it is valid for specifically link type "stylesheet"
to go within body
element, as from https://html.spec.whatwg.org/multipage/links.html#linkTypes it is body-ok.
Note: html
is only permitted to contain two elements, head
followed bybody
. However if you put link
right under html
, the standard regrettably allows this in some situations as it allows omitting <head>
and <body>
start and end tags in some situations. This is due to crappy legacy pages and you should never do this.
Summary: Just put your link
in head
.
Upvotes: 1
Reputation: 23989
According to the HTML 4.01 spec, the <link>
tag must appear in the head section:
This element defines a link. Unlike A, it may only appear in the HEAD section of a document, although it may appear any number of times. Although LINK has no content, it conveys relationship information that may be rendered by user agents in a variety of ways (e.g., a tool-bar with a drop-down menu of links).
Source W3C: http://www.w3.org/TR/html401/struct/links.html#edef-LINK
Upvotes: 5
Reputation: 70416
The tag defines the relationship between a document and an external resource.
The tag is most used to link to style sheets.
Note: The link element must be embedded in the head section, and it can appear any number of times.
From: http://www.w3schools.com/tags/tag_link.asp
The LINK element
(<link>)
is used to add external information related to the HTML document in the header of your document in the HEAD element.
From: http://www.w3.org/QA/Tips/use-links
Upvotes: 5
Reputation: 35064
It's possible to do it.
It's not recommended to do it, because whatever content comes before the <link>
will start rendering and then when the stylesheet is loaded will be rerendered with the new styles. That means that the pageload will be slower (because the browser has to redo all that work) and uglier (because there will be this flash of content with one style that's then restyled to look different).
Upvotes: 22
Reputation: 4360
The <link>
tag does not define structure of a webpage, so it should stay out of the <body>
and <footer>
.
I can't think of any reason why you would ever want/need to put it anywhere other than the <head>
Upvotes: 4
Reputation: 12395
Yes, element is metadata element, whose permitted parent is head, or a element in head.
Upvotes: -1
Reputation: 490233
They are invalid outside of head
, though no browser I know of won't apply the styles if not a child of head
.
Upvotes: 7