12

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?

Dave
  • 3,328
  • 7
  • 26
  • 30
  • Re : Unnecessary loading of CSS - Css is cacheable - the download performance hit will only be taken on the first page load, and the ease of maintenance of having your styles in logically sized files will make this worthwhile IMHO? – StuartLC Aug 09 '10 at 10:08
  • 1
    possible duplicate of [What's the difference if I put css file inside or ?](http://stackoverflow.com/questions/1642212/whats-the-difference-if-i-put-css-file-inside-head-or-body) – Michael Kropat Jun 30 '14 at 14:57

4 Answers4

9

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.

Sergei
  • 2,747
  • 1
  • 17
  • 16
5

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.

darma
  • 4,687
  • 1
  • 24
  • 25
0

Why can't you have several stylesheets and then call them from the pages as needed?

Furthermore, why can't the stylesheets be referenced in the header as opposed to the body?

Evernoob
  • 5,551
  • 8
  • 37
  • 49
0

Yes you can call in the body it will work but this is bad practice. Either you can used the inline CSS stuff for the header & rest will used the by link tag.

Ashay
  • 675
  • 4
  • 13