Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

In an HTML document, does the order of the elements nested inside a <head> ... </head> element matter?

Say I had the following HTML document...

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>My example page</title>
  </head>
  <body>
    <h1>My example page</h1>
  </body>
</html>

Does the order of the elements inside the <head> ... </head> element matter? For example, does it matter if the <meta> element comes before the <title> ... </title> element, or vice versa?

I don't think it will affect your page if you order your elements differently but there is definitely a best practice that you should follow. A quick google search shows quite a few results.
Links:
https://adamhollett.com/posts/2016/07/best-order-for-elements-in-head-tags/
https://stackoverflow.com/questions/27086085/why-does-the-order-of-the-link-elements-in-head-matter

Just to name a few results.

A quick google search shows quite a few results.

Thank you, Brandon! I did conduct a search but must have used the wrong search terms — I couldn't seem to get the same results for some reason!

I don't think it matters as far as <meta> and <title> tags or even generally where you place the <link> or <script> tags in relation to the others, but the order you load the specific <link> and <script> tags is very important. It loads them in order, so if you have a script that depends on another script being loaded, you better have it come second. This can also cause problems with stylesheets. I spent more time than I care to admit with this on some of my first projects where I was loading different javascript libraries.