treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Order of elements in "head" section of html document

  • I am wondering if there is a fixed/correct order for elements appearing in the "head" section of an html document. I'm working on a project and often have style and script elements and am not sure if they should appear in that order and before or after the title of the document. The following is typical of this project:


    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style>
    #container {
    background-color: black;
    }
    </style>

    <script src="http://code.jquery.com/jquery-latest.js"&gt;
    </script>
    <title>Title Here</title>
    </head>


    Is this all right? Should the title precede the style and script? Any help would be appreciated.

    Thanks in advance.
  • I normally do it in this order;
    Meta charset (this should always be before the title)
    Title
    Other meta tags
    Styles

    and move my JavaScript to the end of the document before the closing the body
  • I do the same thing. :)
  • Thanks for the comments.

    And if I had a bit o' script, it would appear just after the JS call before closing the body, like so:


    <script src="http://code.jquery.com/jquery-latest.js"></script&gt;
    <script>
    $(document).ready(function() {
    $('p').fadeOut(8000);
    });
    </script>

    </body>


    Right?