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 How to Make a Website CSS: Cascading Style Sheets What is CSS?

Are style tags applied only inside the head HTML elements?

Just curious. Do style tags work inside the body HTML element besides only working inside the HTML element head which contains meta-data?

1 Answer

-- --
-- --
12,382 Points

Hi Abhishek!

The anwer is yes - the <style> tag should be placed between the <head> tags.

Including CSS directly in your HTML file:

  • Internal: this is the way you're describing in your post - you put the <style> tags in the <head> section and write the CSS between the <style> tags
  • Inline: use the style attribute in your HTML tags

Example of internal CSS:

<html>
<head>
<style>
h1 {
color: #ff0000;
}
</style>
</head>
<body>

Example of inline CSS:

<h1 style="color: #ff0000;">The H1</h1>

Best practice, however, is to use an external file for your CSS. After creating a .css file, you can link to it by using the <link> tag in the <head> section:

<html>
<head>
<style>
<link rel="stylesheet" type="text/css" href="style.css">
</style>
</head>
<body>

Hope this helps. :)

OMG! Thank you so much! I totally forgot about the inline CSS. Thanks for the refresher! Totally connected the dots now. Thanks! :D

-- --
-- --
12,382 Points

Glad I could help. Happy coding! :)