Splitting my pages into parts (eg. header and content), I can't avoid placing links to external stylesheets within <body>
tags.
I don't want to place all styles in one big file or enclose all stylesheets within the <head>
tag because page-specific stylesheets shouldn't be loaded unnecessarily.
In this case, is it appropriate to place a stylesheet within the <body>
tag? Is there a better alternative?
A <link> element can occur either in the <head> or <body> element, depending on whether it has a link type that is body-ok. For example, the stylesheet link type is body-ok, and therefore <link rel="stylesheet"> is permitted in the body.
Each HTML page must include a reference to the external style sheet file inside the <link> element, inside the head section.
No, it is not okay to put a link element in the body tag. See the specification (links to the HTML4.
Any styling you want to do on the <body> should be put into your CSS. And, in fact, <body> is a great place to put all the CSS that should affect the document display as a whole: things like fonts and typography, text and background colors, and other other “default” styling.
Maybe it's not recommended, but yes, it's possible and it's working in all modern browsers. You can place link
or inline style
tags inside body
.
you shouldn't place styles within the body tag, but assuming you're using a server side script (PHP?) to link both header and content, why not write your own class to generate your pages; you could have a method that add styles to the header, and one that outputs the page for instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With