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

CSS How to Make a Website Beginning HTML and CSS Write a CSS Selector and Property

I don't understand why you include a style tag within the body tags. This does not make sense.

The style tag should be in the head section, not within the body tags. This does not make sense.

index.html
<body>
  <style>
  </style>
    <h1>Nick Pettit</h1>
</body>

3 Answers

Why would you place the style tags within the body tags. It should be placed in the head section. This does not make sense. Very odd.

Douglas Counts
Douglas Counts
10,126 Points

It is not that odd. If you place code within the header then you must call it from a loader (onload) because the HTML has not been fully loaded yet and you can get errors as many of the DOM objects may not be instantiated yet. Also these errors may be hard to reproduce reliably, test for, and cause intermittent errors.

Putting code within a script tag just before the closing body tag lets you avoid such loaders, reduces your code size, and is great for short code sections where your hosted CMS may not permit you to upload a separate JavaScript file.

Also with loaders, which JavaScript library got loaded first? Libraries are loaded asynchronously when called from loaders. So the order of loading may be different every time you load the page. You know exactly when your JavaScript loaded within the page flow when you are using script tags.

Later...

Thanks for your time Douglas. I was primarily focused on CSS. As I'm new to web development, I've been informed it's best practice to store your CSS in the head section or preferably in an external css file. I can see that your JavaScript script is usually placed just before the end of the body closing tag??

Thanks again.....an exciting new world.....;)