Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion

external link to CSS file, how does it work?

Hi everyone, this is my very first topic on here although I am no stranger when it comes to online forums. I can't seem to find a section for newbies on here so please don't get annoyed with me if this is not the right place to post!

I'm learning CSS atm.

To link CSS externally, you will need to use this:

<head>

<link rel="stylesheet" type="text/css" href="mystyle.css"> </head>

so my question is, why does it have to be in the "head" section? Can't I just use them wherever I need them? e.g. in the body section or title section.

also I don't understand type="text/css" whats that for? Just trying to understand the syntax of it thats all. Maybe I'm worried too much.

Thanks!

1 Answer

James Barnett
James Barnett
39,199 Points

> why does it have to be in the "head" section

Because that's where web browsers know to look for a CSS file.

> I don't understand type="text/css" whats that for

That tells a web browser that the stylesheet is CSS and not some other kind of stylesheet. However as of HTML5 web browsers now assume any stylesheet is CSS unless they are told differently.