The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS how read external style sheet into HTML body

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #35186

    What is the best way to incorporate an external style sheet into a document which already has the head element defined (by a global template document).

    I run into this all the time and have been inserting the standard

    code after the body. This seems to work okay, but it violates the HTML standard.

    If there is some reason I should not do this, would an “include” of the stylesheet into a style block using PHP be acceptable? (It is my understanding that style blocks are also supposed to go in the head section and that only inline styles in an HTML element are “proper”.



    The link elements should appear within the <head> section.


    I am aware of that, as I wrote in my post.

    The question was “how to read external style sheet into HTML body”, since the head section has already been defined and cannot be modified.


    No I don’t think you can use an include, because it is an html document and will not parse the php include. Unless you adjust your server settings (.htaccess) to parse php language even on html documents. A lot of shared hosting plans do not allow this though I think.

    If they were php documents, it’s too bad you can modify the head just once and allow a variable set in there, then you can always define that variable in body document for whatever you want.



    The issue is not about parsing PHP (the documents are PHP and, as you mentioned, Apache can be told to feed HTML documents through the PHP parser, if necessary).

    The question, again, is whether there is a (“legal”) way to read an external style sheet into the HTML body (not an HTML file) — i.e. between the < body > and the < /body > tags (the spaces around the brackets are intentional).

    Putting the


    I believe this is what inline-styling is for.


    Where does it say the head cannot be modified? You can use javascript to inject a stylesheet into the document head at any time:

    var newStyle = document.createElement("link");
    newStyle.rel = "stylesheet";
    newStyle.href = "http://my-css-file.css";

    And saying something is a standard doesn’t mean not following it is “illegal”, just not a standard practice, but people have been loading stylesheets in the body forever, so maybe you could say it’s common practice.


    thanks Mottie — that looks like a good solution.
    (inline styles would work, they would just be a huge nuisance with large style definitions repeated several hundred times in the document).

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘CSS’ is closed to new topics and replies.